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() {