3

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?

MD XF
  • 7,860
  • 7
  • 40
  • 71
Ternary
  • 2,401
  • 3
  • 31
  • 54
  • I suppose you already gave it a go with firewall and antivirus software totally disabled? –  Mar 11 '14 at 02:23
  • Great point, I should have noted that I believe I have ruled that out. – Ternary Mar 11 '14 at 02:34
  • 1
    Do these sockets connect to remote machines or localhost? Does it happen on various machines or may it be a hardware or software issue on your test machine? Do other applications suffer from this? Does it happen for a test program using one socket too? When does it occur, after a somewhat fixed period of time, or a number of connections or amount of data transferred? – CodeCaster Mar 11 '14 at 14:31
  • possible duplicate of [C# An established connection was aborted by the software in your host machine](http://stackoverflow.com/questions/14304658/c-sharp-an-established-connection-was-aborted-by-the-software-in-your-host-machi) – G.Y Mar 18 '14 at 07:38
  • 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 (per MSDN documentation). I added a simple static counter around each to startup (++) and would all call cleanup if the counter was >0. Problem solved. Would this be best closed or attached to the possible duplicate? – Ternary Mar 18 '14 at 13:34
  • @Ternary The question was very similar to duplicate but it not seems duplicated anymore - I suggest you move the comment you put into an answer and mark it as the answer to your question. it is perfectly alright to answer your own question. – G.Y Mar 19 '14 at 14:10

1 Answers1

1

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.

Ternary
  • 2,401
  • 3
  • 31
  • 54