AS 4.x bug: 15-second timeout in HTTP connections.



There's a bug in AS 4.0 and 4.1 during HTTP downloads over USB with
KeepAlive set to false. I posted about this when 4.0 came out, but now
that I've determined it's still in 4.1, my wrath grows, and I want
everyone to know about the bug. Maybe if I shout loud enough MS will
listen.

I'm using Compact Framework 2.0 (the behavior is also in 1.0), a Pocket
PC 2003 (haven't had a chance to test WM 5.0 yet), Windows XP SP2.

In a C# test app I wrote, I download a 54 k web page, in 2 k blocks,
pausing 1 second between each block. So the download should take a
little over 27 sec. However, after 15 sec I get
"System.Net.Sockets.SocketException: An existing connection was
forcibly closed by the remote host". I can adjust the block size,
total size, and the length of the pause -- the invariant is, I always
get a SocketException after 15 sec.

HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(downloadUrl);
request.Method = "GET";
request.ProtocolVersion = HttpVersion.Version11;
request.KeepAlive = false;

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
int nread = -1;
while (nread != 0)
{
nread = responseStream.Read(buffer, 0, bufSz);
Thread.Sleep(1000);
}

Watching in Ethereal, I see that the desktop downloads all 54 k in a
few millisec, and buffers it. My app slowly reads from that buffer.
(I.e., there's a virtual connection over USB that emulates a direct
connection between the Pocket PC and the server.) After 15 sec of
inactivity in the connection between the desktop and the server, the
desktop closes the connection.

Expected: my app can continue to read from the buffered 54 k until
it's read it all. The virtual connection (USB) is unaffected when the
real connection is closed.

Actual: Once the real connection is closed, the next time my app tries
to read from the stream, it gets a SocketException.

Workaround: Setting KeepAlive true seems to work in both AS 4.0 and
4.1. Just remember that KeepAlive isn't supported in HTTP 1.0.

request.ProtocolVersion = HttpVersion.Version11;
request.KeepAlive = true;

Anyone who wants my test app, just email me.

Jesse.

.



Relevant Pages

  • Detection of a connected laptop via USB.
    ... I am developing a Windows CE 6.0 app that has to detect if a laptop has been ... The laptop is used to download data used by the CE ... connection on the USB is via RequestDeviceNotifications. ...
    (microsoft.public.windowsce.embedded)
  • connect/disconnect ActiveSync programmatically
    ... to XP desktop through USB. ... ie, Activesync connection established. ... When my application starts in the device, I want to disconnect ActiveSync ... When my app ends ActiveSync ...
    (microsoft.public.windowsce.embedded)
  • Re: explorer.exe freezes
    ... My experience is based a wired broadband internet connection. ... early versions of USB were much slower than USB 2. ...
    (microsoft.public.windowsxp.general)
  • Re: ActiveSync 4.1 Still does not work...
    ... AS4.1 installs some USB ... ActiveSync, then allowing Windows to find it again. ... in the system tray for the new 'network adapter' with the 'acquiring network ... If everything seems to be set correctly, but no connection is established, ...
    (microsoft.public.pocketpc.activesync)
  • Re: explorer.exe freezes
    ... I think the thing to do here is replace my card for starters. ... early versions of USB were much slower than USB 2. ... I've had this card for about 3 years, before the USB connection ... slowest way to connect to the internet. ...
    (microsoft.public.windowsxp.general)