Reputation: 57
I'm testing winHTTP out and I've noted that regardless of the timeout values set via WinHttpSetTimeouts, if using an IP address with WinHttpConnect and the IP address is unreachable (i.e. a ping returns "Destination Host Unreacheable"), the timeout of the connection is always 21 seconds even if I set the timeout values much higher.
The value being considered seems to correspond to the dwConnectTimeout value (the 3rd value passed to WinHttpSetTimeouts) as when descreasing this value the timeout occurs sooner but has a ceiling of 21 seconds.
Has anyone experienced this before? Does anyone know why this is occurring and how I prevent it from occurring?
Upvotes: 1
Views: 649
Reputation: 3911
I've found the Question "WinHttpSendRequest ends with 12002 (ERROR_HTTP_TIMEOUT) after 21 seconds no matter what timeout options are set" on social.msdn.microsoft.com and the following Answer from an Windows Networking team member:
Hello:
I'm from the Windows Networking team and can answer the question raised here about why there is a 21 second timeout despite setting the WinHTTP 'Connect' timeout to INFINITE.
This timeout is essentially deprecated due to performance enhancements in the TCP stack in the latest versions of Windows.
Underneath the 'Connect' timeout is really a set of TCP timeouts related to setting up the socket via the 3-leg SYN/ACK exchange. The TCP timeout is about retransmits with back-off and how many is tried by the Winsock stack. The default of these initial packet exchanges is 21 seconds with 2 retransmits (3 overall SYNs) and initial RTO of 3 (3
- 6 + 12). So that explains the timeouts you saw during (presumably) periods of high network congestion.
There is no API exposed in WinHTTP to control those low-level TCP timeouts.
Thx,
David
Microsoft - Windows Networking team
Upvotes: 0
Reputation: 81
After research, it seems there is an underlying TCP connection timeout that cannot be controlled by the WinhttpSetTimeOuts
function. A suggested solution is subtract the elapsed time from the desired Timeout value, then retry the request if there is still time left.
Of course, if you found a better solution since then I'll be glad to hear it.
Upvotes: 3