DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

HttpWebRequest not returning, connection closing

StackOverflow https://stackoverflow.com/questions/604252

Question

I have a web application that is polling a web service on another server. The server is located on the same network, and is referenced by an internal IP, running on port 8080.

Every 15 secs, a request is sent out, which receives an xml response with job information. 95% of the time, this works well, however at random times, the request to the server is null, and reports a "response forcibly closed by remote host."

Researching this issue, others have set KeepAlive = false. This has not solved the issue. The web server is running .NET 3.5 SP1.

Uri serverPath = new Uri(_Url);

// create the request and set the login credentials
_Req = (HttpWebRequest)WebRequest.Create(serverPath);
_Req.KeepAlive = false;
_Req.Credentials = new NetworkCredential(username, password);
_Req.Method = this._Method;

Call to the response:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
_ResponseStream = response.GetResponseStream();

The method for this is GET. I tried changing the timeout, but the default is large enough to take this into account.

The other request we perform is a POST to post data to the server, and we are getting the same issue randomly as well. There are no firewalls affecting this, and we ruled out the Virus scanner. Any ideas to help solving this is greatly appreciated!

Solution

Are you closing the response stream and disposing of the response itself? That's the most frequent cause of "hangs" with WebRequest - there's a limit to how many connections you can open to the same machine at the same time. The GC will finalize the connections eventually, but if you dispose them properly it's not a problem.

OTHER TIPS

I wouldn't rule out network issues as a possible reason for problems. Have you run a ping to your server to see if you get dropped packets that correspond to the same times as your failed requests?

Set the timeout property of FtpWebRequest object to maximum i tried it with 4 GB File and it's working great.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow