From 00d1821daa5b7016fe8a45f7433264b0e9f4b50c Mon Sep 17 00:00:00 2001 From: Devrandom Date: Fri, 22 Aug 2014 11:15:27 -0700 Subject: [PATCH] Fix Orchid deadlock 1 https://github.com/subgraph/Orchid/pull/10 --- .../subgraph/orchid/circuits/CircuitIO.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/orchid/src/com/subgraph/orchid/circuits/CircuitIO.java b/orchid/src/com/subgraph/orchid/circuits/CircuitIO.java index e53cccacad5..0834a3e1e1c 100644 --- a/orchid/src/com/subgraph/orchid/circuits/CircuitIO.java +++ b/orchid/src/com/subgraph/orchid/circuits/CircuitIO.java @@ -37,8 +37,10 @@ public class CircuitIO implements DashboardRenderable { private final BlockingQueue controlCellResponseQueue; 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() { @@ -295,12 +300,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() {