From e9a8d1205e6e5af44aeed32db3329cb62830b414 Mon Sep 17 00:00:00 2001 From: str4d Date: Wed, 12 Mar 2014 20:51:12 -0500 Subject: [PATCH] Deadlock fixes (thx zab) Ref: https://trac.i2p2.de/ticket/1207 --- .../subgraph/orchid/circuits/CircuitIO.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/com/subgraph/orchid/circuits/CircuitIO.java b/src/com/subgraph/orchid/circuits/CircuitIO.java index e53cccac..bbba064d 100644 --- a/src/com/subgraph/orchid/circuits/CircuitIO.java +++ b/src/com/subgraph/orchid/circuits/CircuitIO.java @@ -38,7 +38,9 @@ public class CircuitIO implements DashboardRenderable { private final Map streamMap; private final Object relaySendLock = new Object(); + /** LOCKING: streamMap */ private boolean isMarkedForClose; + /** LOCKING: streamMap */ private boolean isClosed; CircuitIO(CircuitImpl circuit, Connection connection, int circuitId) { @@ -233,19 +235,22 @@ void sendCell(Cell cell) { } void markForClose() { + boolean shouldClose; synchronized (streamMap) { if(isMarkedForClose) { return; } isMarkedForClose = true; - if(streamMap.isEmpty()) { - closeCircuit(); - } + shouldClose = streamMap.isEmpty(); } + if (shouldClose) + closeCircuit(); } boolean isMarkedForClose() { - return isMarkedForClose; + synchronized (streamMap) { + return isMarkedForClose; + } } private void closeCircuit() { @@ -253,7 +258,9 @@ private void closeCircuit() { sendDestroyCell(Cell.ERROR_NONE); connection.removeCircuit(circuit); circuit.setStateDestroyed(); - isClosed = true; + synchronized(streamMap) { + isClosed = true; + } } void sendDestroyCell(int reason) { @@ -295,12 +302,13 @@ StreamImpl createNewStream(boolean autoclose) { } void removeStream(StreamImpl stream) { + boolean shouldClose; synchronized(streamMap) { streamMap.remove(stream.getStreamId()); - if(streamMap.isEmpty() && isMarkedForClose) { - closeCircuit(); - } + shouldClose = streamMap.isEmpty() && isMarkedForClose; } + if (shouldClose) + closeCircuit(); } List getActiveStreams() {