-
Notifications
You must be signed in to change notification settings - Fork 417
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
Server.close() hangs for several seconds/minutes #142
Comments
Can you provide example code that shows this problem? |
Simply running new ChatServer() (from the examples folder) and closing the window causes a long delay before the JVM finally exits. All 3 linux machines I tested it on had the same problem; not sure about Windows. |
I can confirm this problem. It also happens sometimes when trying to connect to the server. I tried to reproduce it. I'm not sure if it works on your machine. // Client#connect calls Client#close() internally. This leads to the process getting stuck (sometimes).
// See Client#close(), selector.selectNow().
Server server = new Server();
server.start();
server.bind(54555, 54777);
// Required. Works otherwise.
new Thread(new Runnable() {
public void run() {
while (true) {
System.out.println("work");
}
}
}).start();
// Wait for the worker to start.
Thread.sleep(1000);
Client client = new Client();
client.start();
// It may be necessary to increase the timeout.
client.connect(5000, "localhost", 54555, 54777); |
I don't recall ever having an issue with connecting (at least not to the same extreme as Server.close()) but I can see how that could be related to the same problem with the internal call to close() in connect(). |
I've occasionally had minor issues while connecting, and definitely have had that issue while disconnecting. I'm on @NathanSweet any updates regarding the provided piece of code? |
@luisfonsivevo Do you happen to call See Issue #82. When I commented the call to my With
|
It looks like it's related to commit a7e9661 Fixed deadlock in EndPoint#close(). When I rolled that back it got working immediately. No more delays. |
+1 I've been experiencing this on the client side too (I don't close the server nearly as often nor the same way, I just kill it, so I don't know if the same problem happens server side). |
I have yet to experience the hang on close issue, but I was seeing exceptions on It looks like there's some gaps in the synchronization logic being used. Calling Order of events that would create the exception:
To avoid the exception, we need to following order of operations:
This approach should mostly get rid of the exception:
Some changes would need to be made to the synchronization logic to avoid this issue, but I think this workaround mostly does the job. It may not do anything for the hang on shutdown though, it's not unlikely that's a separate locking issue. The changes in commit a7e9661 do look suspect, as it pulls the selector usage out of the critical section, so that could definitely be related to the hang reported. |
When calling Server.close(), the thread will hang anywhere from a few seconds to 10+ minutes. On older, slower computers, the hang can last over half an hour. Client.close() has a similar problem but will only hang up to a few seconds. Occasionally, the hang ends with a ClosedSelectorException. This problem was introduced in a7e9661, which was a fix to #93. Tested on Linux (Lubuntu) using the ChatServer example.
The text was updated successfully, but these errors were encountered: