C# All Sockets Go Down

I'm trying to understand what can cause all sockets for a given applicaiton to go down / close and fail to open again.

My application has multiple sockets (http, ftp, etc.) and will run for some time, though at some point (somewhat deterministic), all sockets will go down (I can see this via ProcMon).

I get the dreaded Exception: An established connection was aborted by the software in your host machine exception. Then if I try to open the socket(s) again, I get an error saying WSAStartup may not have been called.

What are some of the tools or techniques I can use to debug such an issue?

Answers


Per suggestion I'm reposting this as the answer.

Thanks for everyone's guidance I was able to solve this issue. I was calling WSAStartup and WSACleanup an uneven amount of times. When the extra WSACleanup hits, it closes all sockets across all threads for the application (see MSDN documentation).

In a multithreaded environment, WSACleanup terminates Windows Sockets operations for all threads.

I added a simple static counter around each to startup (++) and would all call cleanup if the counter was >0. Problem solved.

Hope this helps others.


Need Your Help

I am using jqgrid 4.6.0. Unable to get the available column/Add Column on columnchooser

javascript jquery jqgrid

I want the column chooser like: I have tried in fiddle, couldnt complete. new to fiddle.

Create repeatable HTML table with Javascript

javascript jquery html xml

I need to create multiple tables that hold data. All of the tables will consist of the same fields, but the data for each table is parsed from an XML file using jQuery and Javascript. Currently my ...