As there is no test case, I could not reproduce the problem.
From the description:
There are two threads involved on one UDP socket. One thread is doing a while-loop on receive() and the other thread is closing the socket. Since the reported problem occurs at random time, we can suspect only the receive() to wait for data availability.
Then, how it times out after 6 minutes ?
At Java level the socket is closed and the status would be isClosed()==true. If the same port is used by the server to send data, the receive() comes out successfully and on the next time the SocketException(socket closed) would be thrown.
In the PlainDatagramSocketImpl, timeout is used before recvfrom(). In Win32 WinSock2, setsockopt(SOL_SOCKET, SO_RCVTIMEO) can be used to interrupt the recvfrom() blocking call.
###@###.### 2004-12-22 15:21:42 GMT
The receive() native implementation uses NET_Timeout() and recvfrom() when a timeout value is specified on the socket. This can introduce a time window/gap inbetween these two calls. When another thread updates the socket's fd, it could cause inconsistance fd to be used in this receive() thread.
To fix this, the socket fd is fetched again and validated before proceeding with recvfrom().
###@###.### 2005-2-03 03:53:35 GMT