[Mono-bugs] [Bug 533575] System.Net.HttpWebRequest throws Timeout exception when response is empty

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Aug 30 05:31:34 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=533575

User kenneth at hexad.dk added comment
http://bugzilla.novell.com/show_bug.cgi?id=533575#c2


Kenneth Skovhede <kenneth at hexad.dk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
            Version|2.0.x                       |2.4.x
         Resolution|INVALID                     |




--- Comment #2 from Kenneth Skovhede <kenneth at hexad.dk>  2009-08-30 03:31:29 MDT ---
Alright, I now have a reproducible case.

I appologize for the previous report, it seems to be an issue with my machine,
I have tested on 1.9, 2.0 and 2.4 and all work in the above case.

I am working on getting the ThreeSharp library to work under Mono for my
Duplicati project.

Unfortunately, it is difficult to debug, because you need an Amazon S3 account.

Using wireshark, I have read the S3 server response, and replicated it in an
easier environment.

When the request is sent the TCP handshake occurs, and the HTTP request is
sent.
The response is contained in a single TCP package and contains the
"Transfer-Encoding: chunked" header, and no content length.

Due to ambiguity in the HTTP protocol, the "Connection: close" request header
is ignored with the S3 servers, and the connection is kept open for a long
time.

I have produced the following minimal php script that replicates the S3
response:
<?php
header("HTTP/1.1 404 Not Found");
header("Transfer-Encoding: chuncked");
?>

I have put the script on my server for easy testing, and this is the code that
triggers the bug:
using System;
public class Test 
{
  public static void Main()
  {
    try {
      System.Net.HttpWebRequest req =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.hexad.dk/empty404.php");
      //req.KeepAlive = true; //Set as default
      req.Timeout = 10000;
      req.GetResponse();
    } catch (Exception ex) {
      Console.WriteLine(ex.ToString());
    }
  }
}

The code gives the following output:
System.Net.WebException: The request timed out
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
[0x00000] 
  at System.Net.HttpWebRequest.GetResponse () [0x00000] 
  at Test.Main () [0x00000] 

Setting the timeout to more than 15 sec. (eg. 20 sec.) causes my server to send
the TCP teardown package, which reveals another error:
System.Net.WebException: Error getting response stream (chunked Read2):
ReceiveFailure ---> System.Exception: 
  at System.Net.WebConnection.HandleError (WebExceptionStatus st,
System.Exception e, System.String where) [0x00000] 
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
[0x00000] 
  at System.Net.HttpWebRequest.GetResponse () [0x00000] 
  at Test.Main () [0x00000] 

The S3 server appears to have a timeout above 50 seconds, which is the
ThreeSharp timeout limit, so the error does not appear there.

To verify that the script actually works, using wget works as expected, and
produces a response well within the 10 second limit set in the script.

I've tried looking at the Mono code, but I am unable to locate the problem
further. I would expect that the GetResponse() call returns as soon as it has
read the end-of-header marker (CrLfCrLf), regardless of the "Transfer-Encoding"
header. Putting actual data in response does not seem to affect the results.
I'm guessing that Mono attempts to read out further error information to
present the user with, as a 200 status code does not trigger the bug.
I have put up a script that returns 200 instead:
http://www.hexad.dk/empty200.php

For completeness, I have tested on Mono 2.0.1 and 2.4.2.3 (Ubuntu 9.04 and 9.10
daily) and Mono 2.4.2.3 on windows, all with the same results.
But, using 2.4.2.3 the error that occurs when the teardown is sent is slightly
different:
System.Net.WebException: Error getting response stream (chunked Read2):
ReceiveFailure ---> System.Exception:    at
System.Net.WebConnection.HandleError(WebExceptionStatus st, System.Exception e,
System.String where)

   at System.Net.WebConnection.Read(System.Byte[] buffer, Int32 offset, Int32
size)

   at System.Net.WebConnectionStream.ReadAll()

   at System.Net.HttpWebResponse.ReadAll()

   at System.Net.HttpWebRequest.CheckFinalStatus(System.Net.WebAsyncResult
result)

   at System.Net.HttpWebRequest.SetResponseData(System.Net.WebConnectionData
data)

   at System.Net.WebConnection.ReadDone(IAsyncResult result)

   at System.Net.Sockets.Socket+SocketAsyncResult.Complete()

   at System.Net.Sockets.Socket+Worker.Receive()

  at System.Net.WebConnection.HandleError (WebExceptionStatus st,
System.Exception e, System.String where) [0x00000]

  --- End of inner exception stack trace ---

  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
[0x00000]

  at System.Net.HttpWebRequest.GetResponse () [0x00000]

  at Test.Main () [0x00000]


Using the MS.Net runtime I get a 404 error, but after the timeout limit, eg.
timeout=10 sec -> 18 sec, timeout=20 sec -> 30 sec. Perhaps the MS runtime
detects the timeout/teardown as well, and converts it to a 404 instead?

ThreeSharp: http://www.codeplex.com/ThreeSharp
Duplicati: http://code.google.com/p/duplicati/

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list