Skip to content

Commit

Permalink
Fixed deadlock in EndPoint#close().
Browse files Browse the repository at this point in the history
closes #93
  • Loading branch information
NathanSweet committed May 8, 2015
1 parent 7d6cf16 commit a7e9661
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/com/esotericsoftware/kryonet/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ public void stop () {

public void close () {
super.close();
synchronized (updateLock) { // Blocks to avoid a select while the selector is used to bind the server connection.
}
// Select one last time to complete closing the socket.
synchronized (updateLock) {
if (!isClosed) {
isClosed = true;
selector.wakeup();
try {
selector.selectNow();
} catch (IOException ignored) {
}
if (!isClosed) {
isClosed = true;
selector.wakeup();
try {
selector.selectNow();

This comment has been minimized.

Copy link
@Teiby1

Teiby1 Feb 15, 2016

Thread waits here when calling connect() (which calls close()). Happens on Android 4.2 and 2.3 but not 5.1. When calling it again (starting new connect thread), both threads stop (first the new one then the old) and connection works.

} catch (IOException ignored) {
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/com/esotericsoftware/kryonet/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,13 @@ public void close () {
this.udp = null;
}

synchronized (updateLock) { // Blocks to avoid a select while the selector is used to bind the server connection.
}
// Select one last time to complete closing the socket.
synchronized (updateLock) {
selector.wakeup();
try {
selector.selectNow();
} catch (IOException ignored) {
}
selector.wakeup();
try {
selector.selectNow();
} catch (IOException ignored) {
}
}

Expand Down

0 comments on commit a7e9661

Please sign in to comment.