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?
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.