Wednesday, September 23, 2009

An existing connection was forcibly closed by the remote host.

Usually, this is due to the remote host closing the connection on you, spotty network connections (wireless, 3G, etc). This solution was a new one to me. It turns out that Windows Server 2003 SP2 had an issue with the Scalable Networking Pack. Now to even run into this issue, you need multiple network cards teamed together. Then you need the Scalable Networking Pack installed on top of the Service Pack 2. Microsoft has instructions on how to fix this issue (link) along with some SQL Server guys having issues with it as well (link). To fix it run "Netsh int ip set chimney DISABLED" on all servers, both client and server, having the issue.

Now the fun .NET code issues after all the technical server stuff is out of the way. We had a client/server TCP connection between two servers sitting right next to each other. We developed code that waited for 15 seconds for the data from the server. The client logged that no data was available, the server logged "An existing connection was forcibly closed by the remote host.", which we thought was impossible. So to diagriam it it went like this.

Client A sends request to Server A
Server A reads data, starts long running process.
Client A starts loop to wait for data.
Server A finishes long running process writes to the NetworkStream.
Server A throws errors "An existing connection was forcibly closed by the remote host."
Client A gives up, but still thinks the connection is open and no data is available.


So now I won't have to Google for when this comes up again.