From 50ad0e766641af86efcbed0c726eb65d254676bc Mon Sep 17 00:00:00 2001 From: Devrandom Date: Sat, 23 Aug 2014 14:19:27 -0700 Subject: [PATCH] Fix Orchid deadlock 3 https://github.com/subgraph/Orchid/pull/10 --- .../orchid/connections/ConnectionImpl.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/orchid/src/com/subgraph/orchid/connections/ConnectionImpl.java b/orchid/src/com/subgraph/orchid/connections/ConnectionImpl.java index 1577f29f6..ff3513ac3 100644 --- a/orchid/src/com/subgraph/orchid/connections/ConnectionImpl.java +++ b/orchid/src/com/subgraph/orchid/connections/ConnectionImpl.java @@ -289,29 +289,33 @@ public class ConnectionImpl implements Connection, DashboardRenderable { } private void processRelayCell(Cell cell) { + Circuit circuit; circuitsLock.lock(); try { - final Circuit circuit = circuitMap.get(cell.getCircuitId()); + circuit = circuitMap.get(cell.getCircuitId()); if(circuit == null) { logger.warning("Could not deliver relay cell for circuit id = "+ cell.getCircuitId() +" on connection "+ this +". Circuit not found"); return; } - circuit.deliverRelayCell(cell); } finally { circuitsLock.unlock(); } + + circuit.deliverRelayCell(cell); } private void processControlCell(Cell cell) { + Circuit circuit; circuitsLock.lock(); try { - final Circuit circuit = circuitMap.get(cell.getCircuitId()); - if(circuit != null) { - circuit.deliverControlCell(cell); - } + circuit = circuitMap.get(cell.getCircuitId()); } finally { circuitsLock.unlock(); } + + if(circuit != null) { + circuit.deliverControlCell(cell); + } } void idleCloseCheck() {