RUDP
RUDP copied to clipboard
InputStream blocking on close
Seems, that a read on a socket inputstream is not unblocked, when the local socket instance is closed.
Debugging showed that ReliableSocket.shutdownInput(), which notifies the waiting thread, is not called.
Workaround 1) Explicit close on the InputStream
Sequence
ReliableSocket.getInputStream.close();
ReliableSocket.close();
would unblock the input stream, though may run into exception as the closed-state of the socket is not properly synchronized
Workaround 2) Modification of RUDP libary
Added the kernel of RealiableSocket.shutdownInput() w/o the throw statements in the asynchronous part of ReliableSocket.closeImpl()
https://github.com/GermanCoding/RUDP/blob/master/RUDP/src/net/rudp/ReliableSocket.java, line 1718
This behaves stable, though it's not clear, whether functional requirements hold for other close sequences.
Can you send a PR for 2)?
Here is modified method ReliableSocket.closeImpl() [Sorry for layout]
```
/** * Cleans up and closes the socket. */ protected void closeImpl() { _nullSegmentTimer.cancel(); _keepAliveTimer.cancel(); _state = CLOSE_WAIT;
final Thread t = new Thread()
{
@Override
public void run()
{
// Sam Ginrich 2024-03, unblocking read on inputstream
synchronized (_recvQueueLock)
{
if (!_shutIn)
{
_recvQueueLock.notify();
_shutIn = true;
}
}
_keepAliveTimer.destroy();
_nullSegmentTimer.destroy();
try
{
Thread.sleep(_profile.nullSegmentTimeout() * 2);
}
catch (final InterruptedException xcp)
{
Logger.log(xcp);
}
_retransmissionTimer.destroy();
_cumulativeAckTimer.destroy();
closeSocket();
connectionClosed();
}
};
t.setName("ReliableSocket-Closing");
t.setDaemon(true);
t.start();
}