3

I have a proxy server written in C# that runs as a Windows Service. It listens on 127.0.0.1:xxxxx where xxxxx can be a range of ports from 53500 up.

The proxy works really well but sometimes certain ports stop responding and when I try to telnet to them it says that the request timed out or it did not respond.

I have not been able to reproduce this problem in my development area but I think it has to do with something causing BeginReceive to not be called after EndReceive. The following quote is from a thread about the symptoms I am experiencing.

Similar problem is when using asynchronous communication and there is an execution path which turns out to not call BeginReceive once previous EndReceive was completed. This makes socket ignorant to all further data sent by the remote side.

Is there a way to simulate this situation where a port stops responding. I want to write some code to check if the port is responding before it proceeds with the request. If it is not responding I can remove the listener on that port and add it again. This is a band-aid to keep the proxy from crashing until I can determine the cause of the problem.

I've also added some extra logging to determine what is causing the ports to stop responding.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
modernzombie
  • 1,987
  • 7
  • 25
  • 44
  • 1
    Could you add the code where you suspect the problem is? – Jeff LaFay Feb 09 '11 at 18:06
  • That is a possibility. I was planning to do the port testing in a separate service but I'll take another look. – modernzombie Feb 09 '11 at 18:14
  • Possibly you could try one of the tools recommended in the answers to [this question](http://stackoverflow.com/q/1094760).. – Blorgbeard Feb 09 '11 at 18:16
  • You should try to **stimulate** the failure rather than *simulate* the failure. The problem might be something other than you expect. See: http://books.google.com/books?id=jynA9ECbBsgC&pg=PA30#v=onepage&q&f=false – Zach Johnson Feb 09 '11 at 18:19

1 Answers1

0

I'm taking a stab in the dark, but is the code wrapped in a try finally block?

If a finally block is the only place were you call EndReceive, it might eliminate your problem.

try{
    // processing code
}finally{
    EndReceive()
    BeginReceive()

}
mikerobi
  • 20,527
  • 5
  • 46
  • 42