From a65662e93e4fee01ad0fb0c49bc05b9e37195d0a 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 1577f29f677..ff3513ac34f 100644 --- a/orchid/src/com/subgraph/orchid/connections/ConnectionImpl.java +++ b/orchid/src/com/subgraph/orchid/connections/ConnectionImpl.java @@ -289,29 +289,33 @@ private void processCell(Cell cell) { } 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() {