Discussion:
Winsocks: 10038/WSAENOTSOCK after accept()
(too old to reply)
Moritz Armingeon
2007-09-11 20:43:31 UTC
Permalink
Hello!

I'm running a webserver for a webservice. It's written in unmanaged C++. On
high a frequency of connections, maybe 20 per second, it becomes unstable.
accept() on a new client socket returns INVALID_SOCKET and WSAGetLastError()
returns 10038.

With lower frequencies, the webserver stays stable though. What could be the
cause of such an bevavior? Maybe local socket limitations? Netstat lists
many sockets in state TIMED_WAIT.


Regards, Moritz
Sam Hobbs
2007-09-11 22:18:08 UTC
Permalink
For anyone concerned, this question is posted here because I suggested it be
posted here. I hope this is the right place for it. See:

Winsocks: 10038/WSAENOTSOCK after accept() - MSDN Forums
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2124965&SiteID=1
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged C++.
On high a frequency of connections, maybe 20 per second, it becomes
unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could be
the cause of such an bevavior? Maybe local socket limitations? Netstat
lists many sockets in state TIMED_WAIT.
Regards, Moritz
Michael K. O'Neill
2007-09-12 00:17:25 UTC
Permalink
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged C++. On
high a frequency of connections, maybe 20 per second, it becomes unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError()
Post by Moritz Armingeon
returns 10038.
With lower frequencies, the webserver stays stable though. What could be the
cause of such an bevavior? Maybe local socket limitations? Netstat lists
many sockets in state TIMED_WAIT.
Regards, Moritz
10038 is WSAENOTSOCK, and for a call to accept (and most other winsock
functions), WSAENOTSOCK means that the socket handle parameter did not
reference a valid socket.

It's just about impossible to determine why the handle is no longer valid,
based on the little information provided in the post. It might, for
example, be a multi-threading issue, where the listening socket's handle has
become invalidated in another thread. But we can't tell.

Try posting also in alt.winsock.programming, but be prepared to give more
complete information, such as the socket architecture (IOCP, WSAEventSelect,
whatever)
Arkady Frenkel
2007-09-13 03:59:12 UTC
Permalink
Check maybe that problem connected to backlog, only 5 allowered in client Os
(XP/Vista ) opposite to 200 in Server's Os
Arkady
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged C++.
On high a frequency of connections, maybe 20 per second, it becomes
unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could be
the cause of such an bevavior? Maybe local socket limitations? Netstat
lists many sockets in state TIMED_WAIT.
Regards, Moritz
Alexander Nickolov
2007-09-13 18:46:20 UTC
Permalink
I fail to see how this can relate to an invalid listening socket...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Check maybe that problem connected to backlog, only 5 allowered in client
Os (XP/Vista ) opposite to 200 in Server's Os
Arkady
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged C++.
On high a frequency of connections, maybe 20 per second, it becomes
unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could be
the cause of such an bevavior? Maybe local socket limitations? Netstat
lists many sockets in state TIMED_WAIT.
Regards, Moritz
Arkady Frenkel
2007-09-13 19:03:29 UTC
Permalink
Backlog is property of the server's ( listening ) , not client socket
Arkady
Post by Alexander Nickolov
I fail to see how this can relate to an invalid listening socket...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Check maybe that problem connected to backlog, only 5 allowered in client
Os (XP/Vista ) opposite to 200 in Server's Os
Arkady
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged C++.
On high a frequency of connections, maybe 20 per second, it becomes
unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could be
the cause of such an bevavior? Maybe local socket limitations? Netstat
lists many sockets in state TIMED_WAIT.
Regards, Moritz
Alexander Nickolov
2007-09-13 19:19:33 UTC
Permalink
Well, of course, but when your listening socket is closed
or doesn't exists altogether, there's no backlog, correct?
Besides, the size of the TCP 3-way handshake backlog
is unrelated to accept as it is called only after the connection
is established. It has effect on how many TCP clients can
be actively connecting simultaneously and is completely
isolated from the server code.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Backlog is property of the server's ( listening ) , not client socket
Arkady
Post by Alexander Nickolov
I fail to see how this can relate to an invalid listening socket...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Check maybe that problem connected to backlog, only 5 allowered in
client Os (XP/Vista ) opposite to 200 in Server's Os
Arkady
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged
C++. On high a frequency of connections, maybe 20 per second, it
becomes unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could
be the cause of such an bevavior? Maybe local socket limitations?
Netstat lists many sockets in state TIMED_WAIT.
Regards, Moritz
Arkady Frenkel
2007-09-14 03:56:13 UTC
Permalink
I'm not sure that INVALID_SOCKET was for listening socket, but for working
socket. OP need to check that obviously.
Arkady
Post by Alexander Nickolov
Well, of course, but when your listening socket is closed
or doesn't exists altogether, there's no backlog, correct?
Besides, the size of the TCP 3-way handshake backlog
is unrelated to accept as it is called only after the connection
is established. It has effect on how many TCP clients can
be actively connecting simultaneously and is completely
isolated from the server code.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Backlog is property of the server's ( listening ) , not client socket
Arkady
Post by Alexander Nickolov
I fail to see how this can relate to an invalid listening socket...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Check maybe that problem connected to backlog, only 5 allowered in
client Os (XP/Vista ) opposite to 200 in Server's Os
Arkady
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged
C++. On high a frequency of connections, maybe 20 per second, it
becomes unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could
be the cause of such an bevavior? Maybe local socket limitations?
Netstat lists many sockets in state TIMED_WAIT.
Regards, Moritz
Alexander Nickolov
2007-09-14 16:19:06 UTC
Permalink
That's certainly not possible. WSAENOTSOCK only applies to
the inbound socket descriptor, which in this case is the listening
socket. What you are referring to would be WSAEWOULDBLOCK.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
I'm not sure that INVALID_SOCKET was for listening socket, but for
working socket. OP need to check that obviously.
Arkady
Post by Alexander Nickolov
Well, of course, but when your listening socket is closed
or doesn't exists altogether, there's no backlog, correct?
Besides, the size of the TCP 3-way handshake backlog
is unrelated to accept as it is called only after the connection
is established. It has effect on how many TCP clients can
be actively connecting simultaneously and is completely
isolated from the server code.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Backlog is property of the server's ( listening ) , not client socket
Arkady
Post by Alexander Nickolov
I fail to see how this can relate to an invalid listening socket...
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
Post by Arkady Frenkel
Check maybe that problem connected to backlog, only 5 allowered in
client Os (XP/Vista ) opposite to 200 in Server's Os
Arkady
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged
C++. On high a frequency of connections, maybe 20 per second, it
becomes unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could
be the cause of such an bevavior? Maybe local socket limitations?
Netstat lists many sockets in state TIMED_WAIT.
Regards, Moritz
Moritz Armingeon
2007-09-14 21:03:00 UTC
Permalink
Thanks for your input :)

I believe I found the bug... and it seems to be on the client side. The
client closed each time his connection only with closesocket().
Now I added
shutdown(socket, SD_BOTH)
which cleans the old connection much better. Those many sockets in state
TIMED_WAIT must have been a result of the improper connection termination.
Therefore I conclude WSAENOTSOCK on accept simply means that there is no
space left for further connections. The keyword 'backlog' brought me to
this, it wasn't such a bad hint after all ;)

The last time I cheked, the service was already running about 30min without
problems so far, under high load! That's much improvement against 2 minutes
previously until it crashed. I'll let it run through the weekend to make
sure the problem is fixed...

Regards, Moritz
Post by Moritz Armingeon
Hello!
I'm running a webserver for a webservice. It's written in unmanaged C++.
On high a frequency of connections, maybe 20 per second, it becomes
unstable.
accept() on a new client socket returns INVALID_SOCKET and
WSAGetLastError() returns 10038.
With lower frequencies, the webserver stays stable though. What could be
the cause of such an bevavior? Maybe local socket limitations? Netstat
lists many sockets in state TIMED_WAIT.
Regards, Moritz
Loading...