Search code examples
c#timeouthttpwebrequest

C# HttpWebRequest ignores set timeout


And just immediately throws a a WebException for a timeout.

HttpWebRequest.Timeout is set to 5000 (= 5 seconds). But i get the exception after not even 1 second, what's going wrong there?

Also the default is supposedly 100 seconds, with the default the exception was still thrown immediately.

The exact message from the WebException: The operation has timed out

Does this message mean something else?

following line throws this exception:

HttpWebResponse response = newRequest.GetResponse() as HttpWebResponse;

Even weirder: It just worked for about half a year on at least 2 computers.

I failed to get in the bigger code in a readable fashion (lost the argument with the editor). But since it just worked before i have no clue what would be relevant anyways. The thing literally wasn't touched for months and just worked.


Solution

  • Almost certainly a network/firewall problem specific to the other end of the connection. Thus the sudden problem without changes to my side.

    Connecting to other servers still works.

    But the server in question causes somewhat random connection problems. So my guess is that the connection breaks at a somewhat random point from my applications point of view.

    I contacted the admin and will report back if this gets confirmed.

    Update: Almost correct, forgot to answer. The resolution was: Support end to Win7

    Now many might ask why is that "almost a firewall issue"?

    Well, many admins removed the Win7 default TLS stuff from the whitelist, so their firewall started behaving "hostile" towards this type of request. Basically treating it like a garbage request.

    The correct solution was changing to a supported windows version so .Net would default to a more widely supported standard.

    In other words, yes, server timeout. Server sees non whitelisted request so apparently the acceptable response is not giving it any time whatsoever. Resulting in this seemingly inconsistent behavior with timeouts.