Bug 2992 - Debug HttpWebRequest causes System.Net.WebException: The request timed out
Summary: Debug HttpWebRequest causes System.Net.WebException: The request timed out
Status: REOPENED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: 2.10.x
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-20 13:12 UTC by frederick.permantier
Modified: 2017-05-12 16:21 UTC (History)
8 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
MD solution containing a test. (3.80 KB, application/zip)
2012-03-25 08:12 UTC, Antonius Riha
Details

Description frederick.permantier 2012-01-20 13:12:45 UTC
There seems to be a problem with the combination of Debug, MonoDevelop and WebRequest. 

I'm experiencing strange behavior of the HttpWebRequest class.

Here is the piece of code that is problematic:

[...]
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;

webRequest.Method = POST;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = this.cookieJar;
			
using (Stream requestStream = webRequest.GetRequestStream())
{
}
[...]

The line containing the call to GetRequestStream immediately throws a System.Net.WebException with message "The request timed out".

This only happens when run from inside MonoDevelop and using Mono (I have 2.10.8). That is: the code runs on the Mono framework and not on Microsoft .NET. MonoDevelop itself runs on Microsoft .NET.

The problem seems to occur only when in a debug session. If I right-click on the project containing the above code and use Run with > Mono 2.10.8 then it works as expected.

If I use the Microsoft .NET framework and do a debug session using MonoDevelop it behaves normally.

If I go to the command-line and type "mono --debug bugreport.exe" the program behaves normally.
Comment 2 Jeffrey Stedfast 2012-01-23 11:43:45 UTC
I don't seem to be able to reproduce this. I tried with both MonoDevelop 2.8.5.1 and 2.8.6.1 on Windows.

Here's the test program I used:


using System;
using System.Net;
using System.IO;

namespace WebRequestDebug
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!");
			
			Uri uri = new Uri ("http://www.google.com");
			HttpWebRequest request = WebRequest.Create (uri) as HttpWebRequest;
			request.Method = "POST";
			request.ContentType = "application/x-www-form-urlencode";
			
			using (Stream stream = request.GetRequestStream ()) {
				Console.WriteLine ("Got request stream");
			}
		}
	}
}
Comment 3 frederick.permantier 2012-01-25 00:54:05 UTC
My code was coming from a big solution that was originally created with VS 2010 and I was in the process of porting it to Mono.

Just to make sure that there was not side effet from VS I created a fully new solution from within Monodevelop and copy/pasted the code of Jeffrey in there.

The exact same thing happened.

As soon as GetRequestStream is called I get a System.Net.WebException with message "The request timed out".

Note that the GetRequestStream does not cause any waiting of any sort, as soon as I call it the exception about the timeout is thrown.

What I did this time in detailed steps:

1) Create a new Console Project
2) In the Main.cs file, copy/paste the code from Jeffrey
3) Set the target to Debug|x86 (Mono 2.10.8 (C:\Program Files (x86)\Mono\2.10.8))
4) Set a breakpoint on Console.WriteLine("Hello World!");
5) Press F5 (Start Debug)
6) Step over each line until the GetRequestStream call
7) Step over the GetRequestStream
--> Exception thrown
Comment 4 frederick.permantier 2012-01-25 01:00:36 UTC
I forgot to add the Exception print-out:

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
  at BugReport.MainClass.Main (System.String[] args) [0x0006b] in C:\Users\Frede
rick Permantier\Documents\Development\C#\BugReport\BugReport\Main.cs:28
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object referen
ce not set to an instance of an object
  at BugReport.MainClass.Main (System.String[] args) [0x0006b] in C:\Users\Frede
rick Permantier\Documents\Development\C#\BugReport\BugReport\Main.cs:28
Press any key to continue . . .
Comment 5 frederick.permantier 2012-01-25 01:02:56 UTC
And the one I usually get:

System.Net.WebException: The request timed out
  at System.Net.HttpWebRequest.GetRequestStream () [0x0004a] in C:\cygwin\tmp\mo
nobuild\build\BUILD\mono-2.10.8\mcs\class\System\System.Net\HttpWebRequest.cs:74
2
  at BugReport.MainClass.Main (System.String[] args) [0x00037] in C:\Users\Frede
rick Permantier\Documents\Development\C#\BugReport\BugReport\Main.cs:21
Press any key to continue . . .
Comment 6 pesapower 2012-01-27 19:19:56 UTC
I have the same error ("The request timed out") during the debug with Mono 2.10.8 of this code:

===========================================

NameValueCollection loginData = new NameValueCollection ();
loginData.Add ("username", this.entry_Username.Text);
loginData.Add ("password", this.entry_Password.Text);

WebClient client = new WebClient();
client.BaseAddress = "http://mywordpresssite";

string source = Encoding.UTF8.GetString (client.UploadValues (client.BaseAddress + @"/wp-login.php", loginData));

==========================================

System: Windows 7 x64
Comment 7 Antonius Riha 2012-03-25 08:09:25 UTC
I'm experiencing the same issue.
I followed the steps of Frederick in Comment 3. I tested the program with two runtime versions: 2.10.6 and 2.11.0 (current alpha). The results are almost equal.

----------------------------------

Mono 2.10.6 Test

Debugging (the complete application output is attached)
Debugging yields a timeout WebException at the request.GetRequestStream():

Message: The request timed out
Stack Trace:
at System.Net.HttpWebRequest.GetRequestStream () [0x0004a] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.6\mcs\class\System\System.Net\HttpWebRequest.cs:742 
  at WebRequestDebug.MainClass.Main (System.String[] args) [0x00037] in C:\Users\antonius\Projects\tmp\HttpWebRequestBug\HttpWebRequestBug\Main.cs:18 

In the meantime new threads are created until the gc issues two message boxes "too many threads". After clicking "ok" on one of the message boxes, the mono runtime crashes.


Running the application
Running the program with Ctrl+F5 doesn't cause the timout exception described above. However, another issue emerges: The program doesn't terminate.

----------------------------------

Mono 2.11.0 Test

Debugging (the complete application output is attached)
Debugging yields a timeout WebException at the request.GetRequestStream():

Message: The request timed out
Stack Trace:
  at System.Net.HttpWebRequest.GetRequestStream () [0x0004a] in C:\cygwin\sources\mono\mcs\class\System\System.Net\HttpWebRequest.cs:810 
  at WebRequestDebug.MainClass.Main (System.String[] args) [0x00037] in C:\Users\antonius\Projects\tmp\HttpWebRequestBug\HttpWebRequestBug\Main.cs:18 


Running the application
Everthing works fine.

----------------------------------

From curiosity: What do the cygwin paths in the stack trace mean? I've cygwin installed, but never built mono from source in cygwin. Those paths don't exist on my system.

I've added the complete MD solution that was used for the tests as an attachment. The solution also contains the application output of either debugging test.

----------------------------------

System info:
MonoDevelop 2.8.6.5
Win7 x64
Comment 8 Antonius Riha 2012-03-25 08:12:09 UTC
Created attachment 1575 [details]
MD solution containing a test.
Comment 9 Lorenzo GIRARDIN 2012-03-30 04:44:24 UTC
I'm experiencing the same problem

Below a console application reproducing it
Conditions :
- OS : Windows XP SP3 (but I think it doesn't matter)
- Monodevelop 2.8.6.5 (the same with 2.8.6.4)
- Application runtime (compiled for) : no matter

Executing the compiled application : no problem
Debugging (Soft debugger) on
- Mono-2.8 , Mono-2.10, Mono-2-10.8 --> WebException thrown
- MS .NET -> no problem

_______________________________________________________________
using System.Net;
using System.IO;
using System.Threading;

namespace WebRequestTest
{
	class WebTest
	{
		[STAThread]
		public static void Main (string[] args)
		{
			Console.WriteLine ("--> Main");
			WebTest oWebTest = new WebTest();
			oWebTest.GetWebData();
			Console.WriteLine ("<-- Main");
		}
		
		private void GetWebData()
		{
		    Uri uri = new Uri("http://www.google.com");
		    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
		    request.Method = "POST";
		    using (Stream stream = request.GetRequestStream ()) {
		        Console.WriteLine ("Won't get here in debug with mono runtime");
		    }	
		}		
	}
}
______________________________________________________________________
Exception dump
Unhandled Exception: System.Net.WebException: The request timed out
  at System.Net.HttpWebRequest.GetRequestStream () [0x0003f] in C:\cygwin\tmp\mo
nobuild\build\BUILD\mono-2.8\mcs\class\System\System.Net\HttpWebRequest.cs:691
  at WebRequestTest.WebTest.GetWebData () [0x00022]
Comment 10 Jeffrey Stedfast 2012-03-30 08:03:01 UTC
Reopening and reassigning to core Mono devs, I don't see how this could be a MonoDevelop bug.
Comment 11 Jeffrey Stedfast 2012-03-30 08:05:39 UTC
Could also be a runtime bug... Zoltan? Any ideas?
Comment 12 Lorenzo GIRARDIN 2012-03-31 16:19:04 UTC
I've also noticed that if the above code(anything related to WebRequest) is part of a project where threading is used,  the scheduler and any way to synch threads is going to hell. In other words a Thread.sleep(millies) won't wait "millies", a ManualResetEvent will have .WaitOne() uneffective.

But mind, all in Debug, not just running the application... Infact to be able to go on with my project, I'm compiling mono 2.10.8 and debugging MS.Net

Lorenzo
Comment 13 Rony Barbosa 2012-05-17 06:10:20 UTC
Hi everybody,

I'm with the same problem. 

But i know now the causes. 

The debug of Linux are different of windows debug. Linux debug shows us more detailed or the real cause of the problem.

At windows show a "The request timed out" but on Linux show a problem with the Cookie.

Here is point about a problem with the cookie implementation. When the response is returned the atributte (a cookiecollection) "Cookie" is empty, no matter if there are cookies (you can see it on the header).

I'm using mono 2.10.8. The problem is in the class "cookie". For some reason it is throws a exception
Comment 14 Alain 2017-05-12 16:21:32 UTC
Hi,

I have a similar problem.

We currently do not know how to explain it.

We have a identical webservice that runs on 3 servers.

Depending on the user, it is switched to server 1, 2 or 3.

It happens on server 3 for example to have this message: The request timed out, while a minute before, it logged on server 1 without a problem.

In our logs, we see at this time no access to the server but on the server 1.

I do not know if this can be the cause, but the url on server 1 starts with. Https: //www.medinect.be .... and on server 3, https: //server3.medinect.be ...

Thank you for your help

Note You need to log in before you can comment on or make changes to this bug.