Commit 389c17c7 authored by Dave Cridland's avatar Dave Cridland

Do not synchronize on isClosed()

There is a deadlock while reading the state variable if close() is running.

This switches the state to be volatile instead - it's only written to inside
the lengthy close() lock, so this should be reasonable.
parent 47d44217
...@@ -116,7 +116,7 @@ public class NIOConnection implements Connection { ...@@ -116,7 +116,7 @@ public class NIOConnection implements Connection {
* keep this flag to avoid using the connection between #close was used and the socket is actually * keep this flag to avoid using the connection between #close was used and the socket is actually
* closed. * closed.
*/ */
private State state; private volatile State state;
/** /**
* Lock used to ensure the integrity of the underlying IoSession (refer to * Lock used to ensure the integrity of the underlying IoSession (refer to
...@@ -288,7 +288,7 @@ public class NIOConnection implements Connection { ...@@ -288,7 +288,7 @@ public class NIOConnection implements Connection {
session = owner; session = owner;
} }
public synchronized boolean isClosed() { public boolean isClosed() {
return state == State.CLOSED; return state == State.CLOSED;
} }
...@@ -297,7 +297,7 @@ public class NIOConnection implements Connection { ...@@ -297,7 +297,7 @@ public class NIOConnection implements Connection {
} }
public void deliver(Packet packet) throws UnauthorizedException { public void deliver(Packet packet) throws UnauthorizedException {
if (isClosed()) { if (state != State.RUNNING) {
// OF-857: Do not allow the backup deliverer to recurse // OF-857: Do not allow the backup deliverer to recurse
if (backupDeliverer == null) { if (backupDeliverer == null) {
Log.error("Failed to deliver packet: " + packet.toXML()); Log.error("Failed to deliver packet: " + packet.toXML());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment