mike
mike

Reputation: 3166

web calls never timing out

I have a number of applications using various web technologies such as SOAP, WCF Services, or just simple XmlReader. However they all seem to suffer the same problem of missing the timeout and hanging infinitely if the internet connection suffers problems at the wrong time.

I have set the timeout in all scenarios to something small, e.g. for wcf

closeTimeout="00:00:15" openTimeout="00:00:15" 
receiveTimeout="00:00:15" sendTimeout="00:00:15"

or for soap

_Session.Timeout = (int)TIMEOUT.TotalMilliseconds;

These timeouts do generally get hit, however it appears there is some special case where if the internet drops out at the right time, the call will hang and never time out (using synchronous calls).

I was considering starting up a timer every time I make a call, and using the appropriate .Abort() function if the timer expires to cancel the call. However, I was wondering if there was a simpler way to fix the issue and ensure the timeout gets hit.

Does anyone know why this occurs, and if so what a clean/simple/good way is to ensure the calls always time out?

Upvotes: 4

Views: 2135

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

I can guess at why it occurs, but without giving a solution :(

I suspect it's getting caught up on DNS resolution. I've seen various situations where that "doesn't count" - e.g. where it ends up happening on the initiating thread of an asynchronous call, or where it's definitely not been included in timeouts.

If you're able to reproduce this by pulling out your network cable, I'd suggest using Wireshark to confirm my guess - that would at least suggest further avenues for investigation. Maybe there's a DNS timeout somewhere in the .NET stack which is normally infinite but which can be tweaked, for example.

Upvotes: 4

Related Questions