WebResponse Close call hangs

I'm currently seeing a WebResponse.Close() call "hang" running CF2 from VS.NET Beta 2 running on a standard Pocket PC 2003 SE emulator.

The HTTP request is being made against a Live365-based audio streamer (MP3 streamer) and the code below hangs every time I run it. The stream it is opening is thus very large and is binary rather than textual - but in the example code below I don't even read any of that stream.

The code does not hang under full .NET running on my XP box.

Can anyone suggest a solution or workaround for this

Thanks

Stuart



Code is:

string inputURL = "http://216.235.81.3:20012";


WebResponse
response = null
;

Uri myUri = new Uri(inputURL, UriKind.Absolute);


WebRequest
req = WebRequest
.Create(myUri);

response = req.GetResponse();


if
(response != null
)

{

// this line hangs :-(

response.Close();

}




Answer this question

WebResponse Close call hangs

  • briankerri

    If KeepAlive is false, or ProtocolVersion is HttpVersion.Version10, there could be no other WebRequests simultaneously sharing this same socket. And yet, even in those cases Abort() does not abort, but stall. This is most definitely a bug.

  • therock

    I don't have access to a real device at this moment (my pocket PC is in for repair and I'm waiting for some WM5 hardware...) so I can't test it right now - but the code I  posted before is very easy to put into a test app. Is the problem replicated on your emulator  On your test headware

    Using the WinPCAPs Analyzer tool I see the following type of trace - with the data transfer continuing until I use Task manager to stop the test application.

    N. Time Data Link Network Transport Application
    1 09:05:33.206085 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.3 (Len 48) TCP: Port 8859 => 20012 (SYN ) Seq 2354694283, Ack 0, Win 16384
    2 09:05:33.357897 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.3 => 192.168.0.25 (Len 48) TCP: Port 20012 => 8859 (SYN ACK ) Seq 3161557439, Ack 2354694284, Win 8760
    3 09:05:33.357949 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.3 (Len 40) TCP: Port 8859 => 20012 (ACK ) Seq 2354694284, Ack 3161557440, Win 17520
    4 09:05:33.461039 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.3 (Len 102) TCP: Port 8859 => 20012 (ACK PUSH ) Seq 2354694284, Ack 3161557440, Win 17520 Data
    5 09:05:33.613160 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.3 => 192.168.0.25 (Len 40) TCP: Port 20012 => 8859 (ACK ) Seq 3161557440, Ack 2354694346, Win 8760 Data
    6 09:05:33.614139 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.3 => 192.168.0.25 (Len 60) TCP: Port 20012 => 8859 (ACK PUSH ) Seq 3161557440, Ack 2354694346, Win 8760 Data
    7 09:05:33.739477 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.3 (Len 40) TCP: Port 8859 => 20012 (ACK ) Seq 2354694346, Ack 3161557460, Win 17500
    8 09:05:33.892867 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.3 => 192.168.0.25 (Len 85) TCP: Port 20012 => 8859 (FIN ACK PUSH ) Seq 3161557460, Ack 2354694346, Win 8760 Data
    9 09:05:33.892926 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.3 (Len 40) TCP: Port 8859 => 20012 (ACK ) Seq 2354694346, Ack 3161557506, Win 17455
    10 09:05:34.098801 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.3 (Len 40) TCP: Port 8859 => 20012 (FIN ACK ) Seq 2354694346, Ack 3161557506, Win 17455
    11 09:05:34.199221 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 48) TCP: Port 8860 => 14802 (SYN ) Seq 112092021, Ack 0, Win 16384
    12 09:05:34.250539 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.3 => 192.168.0.25 (Len 40) TCP: Port 20012 => 8859 (ACK ) Seq 3161557506, Ack 2354694347, Win 8760 Data
    13 09:05:34.351169 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 48) TCP: Port 14802 => 8860 (SYN ACK ) Seq 3564357782, Ack 112092022, Win 8760
    14 09:05:34.351224 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092022, Ack 3564357783, Win 17520
    15 09:05:34.356927 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 107) TCP: Port 8860 => 14802 (ACK PUSH ) Seq 112092022, Ack 3564357783, Win 17520 Data
    16 09:05:34.510079 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 40) TCP: Port 14802 => 8860 (ACK ) Seq 3564357783, Ack 112092089, Win 8760 Data
    17 09:05:34.511761 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 57) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564357783, Ack 112092089, Win 8760 Data
    18 09:05:34.640778 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564357800, Win 17503
    19 09:05:34.794308 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 183) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564357800, Ack 112092089, Win 8760 Data
    20 09:05:34.941219 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564357943, Win 17360
    21 09:05:35.008968 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564359403, Ack 112092089, Win 8760 Data
    22 09:05:35.009014 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564357943, Win 17360
    23 09:05:35.015772 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564357943, Ack 112092089, Win 8760 Data
    24 09:05:35.015839 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564359943, Win 17520
    25 09:05:36.085310 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564361403, Ack 112092089, Win 8760 Data
    26 09:05:36.085360 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564359943, Win 17520
    27 09:05:36.091939 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564359943, Ack 112092089, Win 8760 Data
    28 09:05:36.092006 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564361943, Win 17520
    29 09:05:37.109618 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564363403, Ack 112092089, Win 8760 Data
    30 09:05:37.109664 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564361943, Win 17520
    31 09:05:37.116223 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564361943, Ack 112092089, Win 8760 Data
    32 09:05:37.116290 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564363943, Win 17520
    33 09:05:38.030944 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564365403, Ack 112092089, Win 8760 Data
    34 09:05:38.030990 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564363943, Win 17520
    35 09:05:38.037750 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564363943, Ack 112092089, Win 8760 Data
    36 09:05:38.037817 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564365943, Win 17520
    37 09:05:39.054963 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564367403, Ack 112092089, Win 8760 Data
    38 09:05:39.055010 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564365943, Win 17520
    39 09:05:39.061785 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564365943, Ack 112092089, Win 8760 Data
    40 09:05:39.061855 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564367943, Win 17520
    41 09:05:40.078799 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564369403, Ack 112092089, Win 8760 Data
    42 09:05:40.078844 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564367943, Win 17520
    43 09:05:40.085618 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564367943, Ack 112092089, Win 8760 Data
    44 09:05:40.085686 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564369943, Win 17520
    45 09:05:41.102768 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564371403, Ack 112092089, Win 8760 Data
    46 09:05:41.102815 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564369943, Win 17520
    47 09:05:41.109487 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564369943, Ack 112092089, Win 8760 Data
    48 09:05:41.109523 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564371943, Win 17520
    49 09:05:42.012136 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564373403, Ack 112092089, Win 8760 Data
    50 09:05:42.012184 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564371943, Win 17520
    51 09:05:42.019008 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564371943, Ack 112092089, Win 8760 Data
    52 09:05:42.019076 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564373943, Win 17520
    53 09:05:43.047926 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564375403, Ack 112092089, Win 8760 Data
    54 09:05:43.047970 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564373943, Win 17520
    55 09:05:43.054678 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564373943, Ack 112092089, Win 8760 Data
    56 09:05:43.054744 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564375943, Win 17520
    57 09:05:44.071843 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 580) TCP: Port 14802 => 8860 (ACK PUSH ) Seq 3564377403, Ack 112092089, Win 8760 Data
    58 09:05:44.071890 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 52) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564375943, Win 17520
    59 09:05:44.078558 Eth: 00095B-6D3052 => 000423-7B4BD5 IP: 216.235.81.25 => 192.168.0.25 (Len 1500) TCP: Port 14802 => 8860 (ACK ) Seq 3564375943, Ack 112092089, Win 8760 Data
    60 09:05:44.078624 Eth: 000423-7B4BD5 => 00095B-6D3052 IP: 192.168.0.25 => 216.235.81.25 (Len 40) TCP: Port 8860 => 14802 (ACK ) Seq 112092089, Ack 3564377943, Win 17520


  • Dan1

    It appears the issue is due to the large size of the file being downloaded. The file size being transmitted over http is around 4.5 MB and when you close a response, the extra data that has not been read by the client needs to be drained so that other http requests using the same socket can operate properly without reading in data mean't for the previous http request.

    In this specific case, even though the client looks like its hung its actually draining the socket stream which takes a long time (took me somthing like an hour).

    You can speed this up by reading the data in the application passing in a large buffer.

    Thanks,
    Sandy

  • deepakleo2003

    Thanks for that information.

    I've tried the workaround you suggested using the loop:

    Stream s = response.GetResponseStream();

    byte[] buffer = new byte[100000];

    while (true)

    {

          if (s.Read(buffer, 0, 100000) <= 0)

          {

             break;

          }

    }


    - but it still takes an excessive length of time to complete - to the appearance of my UI thread it does seem to "hang".

    I've also tried using the asynchronous .BeginGetResponse and .BeginRead APIs but these still don't seem to help speed up the shutdown of the transfer either.

    Are there any other suggestions you can provide about how to speed this up Specifically is there any way I can just abandon the data transfer - that I can close the underlying socket and move on without transferring the entire file

    Thanks again for your help so far.

    Stuart

  • Scoper

    Hi Stuart,

    Would it be possible to capture packet traces using a network sniffer like ethereal and provide that capture here It would be very useful in debugging the issue.

    Does this happen only on an emulator or does it also occur when you deploy to a device

    Thanks,
    Sandy

  • Sverk

    The answer from MS was that this is a feature.

    I ended up writing my own little HTTP stack so that I could cancel it when I wanted to.... and I'm still fixing bugs and issues in the stack :-/

    Good luck!



  • Richard Masse

    I too can find NO way to cancel a download without waiting for the entire stream to empty (which defeats the point of canceling the thing).

    HttpWebRequest.Abort() does not work. Setting the Request = null does not work. Closing the response does not work. Closing the stream does not work. Once you've gotten that responseStream you are going to hang until the entire file transfers down. How the heck do you CANCEL it I don't want it. I want the thing to die!

  • Kakurady

    You can try aborting the http request using HttpWebRequest.Abort(). This closes the underlying socket.
  • WebResponse Close call hangs