I have some InternetOpenUrl requests that are strangely timing out. The endpoint is there and the URL is correct. This happens in a synchronous loop inside an activex control, and about the 6th time it executes, it times out without hitting the server.
HINTERNET hINet = InternetOpen(TEXT("InetURL/1.0"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
/*hangs*/ HINTERNET hFile = InternetOpenUrl( hINet, url.c_str(), headers, headersLen, dwFlags, dwContext);
GetLastError just returns 12002 operation timed out. Here’s the full snippet: http://gist.github.com/559317
Interestingly, if I change the InternetOpen flag to INTERNET_OPEN_TYPE_DIRECT, and fiddler is NOT running, I get the failure (after a few successful requests), and if i run fiddler, the requests all succeed.
so far this has been replicated on Win7/IE8, and Vista64/IE8, XP/IE6
OK so I originally thought EricLaw was correct and commented: “my particular problem was that i had javascript ajax calls occuring after each control ajax call. this creates a race condition and eventually 4 javascript ajax calls hadn’t returned when i made an ajax call inside the control. (yeah, i misstated my environment in the original question)”
this comment is incorrect.
the issue is actually the issue discussed here:
“Your ActiveX control has a common defect that single-threaded apartment
(STA) ActiveX & COM objects must avoid: STA COM objects cannot perform
blocking operations on the STA thread, unless the COM object also pumps
Windows messages. Therefore, if your control needs to perform a synchronous
blocking operation, it needs to implement a Windows message pump while
waiting for the blocking operation to complete.”
this solved the issue (and opened a whole new can of worms). if you run into this you’re welcome to comment here and I’ll explain better.