[Mono-devel-list] HttpWebRequest/WebRequest Timeout Bug

Andrew Gleave Andrew.Gleave at ifgmgt.com
Thu Mar 24 09:28:09 EST 2005


Hi,
    I posed a mail about this issue before but got no response, so I
decided to put together a test app to demonstrate the issue.  If you run
the following app using the MS .NET framework you will get a timeout
exception thrown after ~10secs, which is the correct behaviour.
However, using the mono runtime the timeout exception is not thrown for
3mins 9secs for the first run, then 6mins 19secs for the second and so
on.  The IP that is defined is just a dud, and doesn't exist, so the
timeout should be thrown after the elapsed time has expired. 
    If anyone has any insight, please could they let me know.  
 
Thanks a lot
 
Andrew Gleave

Software Engineer

IFG Management Limited 
http://www.ifgint.com <http://www.ifgint.com> 

 

/*******************************************************/

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;

}

}

}

/*******************************************************/

 

 

The information contained in this E-mail is confidential. It may also be legally privileged. It is intended only for the stated addressee(s) and access to it by any other person is unauthorised. If you are not an addressee, you must not disclose, copy, circulate or in any other way use or rely on the information contained in this E-mail. Such unauthorised use may be unlawful. If you have received this E-mail in error, please inform us immediately and delete it and all copies from your system.

Due to the fact that this E-mail could become corrupted or altered during transmission, any advice which it contains should not be relied upon unless subsequently confirmed by fax or letter signed by or on behalf of this company.

E-mails do not constitute compliance with any time limits or deadlines. 

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared 
by NetIQ MailMarshal
#####################################################################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050324/7196aaa6/attachment.html 


More information about the Mono-devel-list mailing list