ASynch sockets race

G

Guest

I have a fully asynch socket server application. I find however that
sometimes it locks up.
The client sends me a packet before I have posted a BeginRead. My beginread
then completes but I never get called back. Both sides end up waiting for
each other.

THe IAsyncResult return by BeginRead has IsCompleted=false

At first I thought it might be becuase I was doing some sycn IO during
client connection but I have made that all async too and I still get the
occasional lockup

I am sure I am doing something dumb but I cant see what. I always fail if my
trace show client send packet followed by server beginread but if the 2
process time just slighly differnt and I get server beginread then client
send packet then all is fine.

If I kill the client and run it again all is fine. The server pending
callback is invoked saying that the socket closed and the server cleans up
OK. Then we get into the same race with this next client
 
P

Peter Duniho

I have a fully asynch socket server application. I find however that
sometimes it locks up.
The client sends me a packet before I have posted a BeginRead. My
beginread
then completes but I never get called back. Both sides end up waiting
for each other.

Well, as you might guess, that shouldn't be a problem. Once the socket is
connected, it should not matter whether the server has actually posted a
receive yet, the data should still get through once the receive has been
posted, eventually.

I do suspect you've got a bug in your own code, but since you didn't post
any code it's hard to say. The usual practice is to post a
concise-but-complete sample of code that reliably reproduces the problem.
If you do so, then perhaps you'll be able to get a better answer.

By the way, I will note that I'm assuming you have a connection-oriented
socket (eg TCP), since you mention a "connection" and closing the
connection. However, if you are using UDP then the behavior you're seeing
is not necessarily unexpected, and you need to code around the possibility
of not receiving data (among other things).

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top