Skip to content

Commit

Permalink
Fix Orchid deadlock 1
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom authored and mikehearn committed Aug 23, 2014
1 parent 4610490 commit 00d1821
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions orchid/src/com/subgraph/orchid/circuits/CircuitIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ public class CircuitIO implements DashboardRenderable {
private final BlockingQueue<Cell> controlCellResponseQueue;
private final Map<Integer, StreamImpl> streamMap;
private final Object relaySendLock = new Object();


/** LOCKING: streamMap */
private boolean isMarkedForClose;
/** LOCKING: streamMap */
private boolean isClosed;

CircuitIO(CircuitImpl circuit, Connection connection, int circuitId) {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Stream> getActiveStreams() {
Expand Down

0 comments on commit 00d1821

Please sign in to comment.