[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

Socket Wierdness



I just wasted a bunch of time trying to figure out why my program was
suddenly encountering the following error return code from the
"connect" system call:

     ECONNREFUSED        The attempt to  connect  was  forcefully
                         rejected.   The  calling  program should
                         close(2)  the  socket  descriptor,   and
                         issue another socket(2) call to obtain a
                         new descriptor before attempting another
                         connect(2) call.

I would change some minor thing and the problem would go away.  I
would change some other minor thing, and the problem would reappear.
Frequently it was impossible to imagine the relationship between what
I changed and whether "connect" would succeed.  Finally I noticed that
it sometimes changed behavior when I changed *nothing at all*.  Note
that this is an attempt (in all cases) to connect to a socket to a
task on the same machine, and the program itself should be purely
deterministic.  My only guess is that "connect" succeeds
intermittently and unpredictably.  Is this a bug in Unix?  Is this
normal socket behavior that I was unaware of?  Does the mysterious
description (above) from the man page mean that I should write my code
to loop until "connect" succeeds?  Does anyone know what's up with
this?  Thanks.