ID: Q126346
The information in this article applies to:
Packets between the TCP, UDP, and IP layers are lost.
There appears to be a problem with a race condition between two threads that share a socket where one is closing a socket while the other tries to call recvfrom() on the same socket. This causes problems the next time a socket is bound to the same UDP port.
The vendor should implement a workaround within the application so that this race condition does not occur.
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
This Sockets/UDP problem was discovered while testing the TX1000 NCPI driver for Windows NT. Here are some notes showing what appears to be happening:
Thread 1 Thread 2
-------- ---------
Create DGRAM socket x
Bind socket x to:
IPADDR = ANY
PORT = 1571
Create thread 2 ----------------->
RecvFrom on socket x
...
Packet received on x (recvfrom completes)
<---------------signal main thread
Process rec'd packet wait for main thread to consume buffer
Signal buffer available--------->
RecvFrom on socket x
... { repeats many times }
Packet received on x (recvfrom completes)
<---------------signal main thread
Process rec'd packet wait for main thread to consume buffer
Signal buffer available--------->
Application done (1) RecvFrom on socket x
(2) close socket x
(3) RecvFrom fails with expected error
Thread terminates
Usually, events occur in sequence (1, 2, then 3). In this normal case, the
socket is cleared correctly, and everything works the next time the
application runs.
Packet received on x (recvfrom completes)
<---------------signal main thread
Process rec'd packet wait for main thread to consume buffer
Signal buffer available--------->
Application done
(1) close socket x (2) RecvFrom on socket x
(3) RecvFrom fails with expected error
Thread terminates
In this case, the sequence is slightly different. The closesocket()
function from main thread starts, but does not complete, before thread 2
runs. While thread 1 is suspended awaiting completion of closesocket(),
thread 2 runs and posts next recvfrom() on same socket. The closesocket()
function completes successfully, and recvfrom() fails as in normal case.
But the next time the application runs and binds to the same UDP port, the
following occurs:
netstat -s -p udp
Additional query words:
Keywords : kbnetwork kbIP kbNTOS350 kbSDKPlatform kbWinsock kbGrpNet
Issue type : kbbug
Last Reviewed: August 6, 1998