Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputStream blocking on close #4

Open
SamGinrich opened this issue Mar 4, 2024 · 2 comments
Open

InputStream blocking on close #4

SamGinrich opened this issue Mar 4, 2024 · 2 comments

Comments

@SamGinrich
Copy link

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.

@GermanCoding
Copy link
Owner

Can you send a PR for 2)?

@SamGinrich
Copy link
Author

SamGinrich commented Mar 9, 2024

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();
}
	

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants