[Mono-bugs] [Bug 74177][Wis] New - HttpWebRequest GetResponse() Timeout

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 29 Mar 2005 07:46:16 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by andrew.gleave@ifgmgt.com.

http://bugzilla.ximian.com/show_bug.cgi?id=74177

--- shadow/74177	2005-03-29 07:46:16.000000000 -0500
+++ shadow/74177.tmp.1626	2005-03-29 07:46:16.000000000 -0500
@@ -0,0 +1,167 @@
+Bug#: 74177
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details: Linux (RH 9), Windows(Win2K) & Mac OS X(10.3.8)
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: Andrew.Gleave@ifgmgt.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: HttpWebRequest GetResponse() Timeout 
+
+Description of Problem:
+The HttpWebRequest class does not throw a Timeout WebException after the
+correct period if the remote address/location does not exist, or does not
+respond within the timeout period.
+
+Steps to reproduce the problem:
+1. Compile and run the following source using the latest build of mono and
+the class libraries from svn (I'm using revision 42323).
+2. Specify a non-existant address or invalid port for web server URL.
+
+Actual Results:
+The RequestTest instances do not timeout after trying to resolve the
+address for the specified period. Or, the first instance times out
+correctly and the rest either do not time out, or timeout after seemingly
+random periods.
+
+Expected Results:
+When running under the .NET Framework (1.1), the WebRequest(HttpWebRequest)
+throws a timeout WebException after the correct period has elapsed.
+
+How often does this happen? 
+Every time
+
+
+Additional Information:
+
+Source:
+
+using System;
+using System.Text;
+using System.Net;
+using System.Timers;
+
+public class Runner
+{
+	private const string url = "http://14.125.254.1:80/";
+
+ 
+	public static void Main()
+	{
+		RequestTest[] events = new RequestTest[5];
+
+		for(int i = 0; i < 5; i++)
+            events[i] = new RequestTest(url, 15000, i);
+		
+		Console.WriteLine("Type 'quit' to exit");
+		
+		Listen:
+		string input = Console.ReadLine();
+
+		if(input == "quit")
+			for(int i = 0; i < 5; i++)
+			{
+				events[i].Dispose();
+				events[i] = null;
+			}
+		else
+			goto Listen;
+	}
+ }
+
+public class RequestTest : IDisposable
+{
+	int m_ID;
+	HttpStatusCode m_StatusCode;
+	string m_ContentType;
+	string m_URL = string.Empty;
+	TimeSpan m_TestDuration = new TimeSpan(0, 0, 0);
+	System.Timers.Timer m_Timer = new System.Timers.Timer();
+
+	public RequestTest(string url, int interval, int id)
+	{
+		m_ID = id;
+		m_URL = url;
+		m_Timer.Elapsed += new ElapsedEventHandler(ExecuteRequest);
+		m_Timer.Interval = interval;
+		m_Timer.AutoReset = true;
+		m_Timer.Enabled = true;
+	}
+
+	public void ExecuteRequest(object source, ElapsedEventArgs e)
+	{
+		HttpWebRequest request = null;
+		HttpWebResponse response = null;
+		DateTime requestStart = DateTime.Now;
+			
+		try
+		{
+			Console.WriteLine("{0} - Executing. ID: {1}", DateTime.Now, m_ID);
+
+			//create the request
+			request = (HttpWebRequest)WebRequest.Create(m_URL);
+
+			request.MaximumAutomaticRedirections = 4;
+			request.MaximumResponseHeadersLength = 4;
+			request.Timeout = 10000;
+
+			response = (HttpWebResponse)request.GetResponse();
+
+			//get the status and content type
+			m_StatusCode = response.StatusCode;
+			m_ContentType = response.ContentType;
+
+			//mark the end of the test 
+			m_TestDuration = DateTime.Now - requestStart;
+
+			Console.WriteLine("{0} - Completed. ID: {1} Duration: {2}",
+DateTime.Now, m_ID, m_TestDuration);
+
+		}
+		catch(WebException ex)
+		{
+			//mark the end of the test 
+			m_TestDuration = DateTime.Now - requestStart;
+
+			Console.WriteLine(string.Format("{0} - Duration: {1} ID: {2}
+WebException: {3}", 
+					DateTime.Now, m_TestDuration, m_ID, ex.Message));
+		}
+		catch(Exception ex)
+		{
+			Console.WriteLine(string.Format("{0} - Duration: {0} ID: {1} Exception:
+{2}", 
+					DateTime.Now, m_TestDuration, m_ID, ex.Message));
+		}
+		finally
+		{
+			m_StatusCode = 0;
+			m_ContentType = string.Empty;
+
+			request = null;
+
+			if(response != null)
+			{
+				response.Close();
+				response = null;
+			}
+		}
+	}
+
+	public void Dispose()
+	{
+		if(m_Timer != null)
+		{
+			m_Timer.Dispose();
+			m_Timer = null;
+		}
+	}
+}