diff --git a/server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java b/server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java index 7929897e3..18429ed7a 100644 --- a/server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java +++ b/server/src/main/java/com/hedera/block/server/mediator/LiveStreamMediatorImpl.java @@ -152,18 +152,17 @@ public void subscribe(final EventHandler> h public void unsubscribe(final EventHandler> handler) { // Remove the subscriber - if (subscribers.containsKey(handler)) { + final var batchEventProcessor = subscribers.remove(handler); + if (batchEventProcessor == null) { + LOGGER.log(System.Logger.Level.ERROR, "Subscriber not found: {0}", handler); - final var batchEventProcessor = subscribers.remove(handler); + } else { // Stop the processor batchEventProcessor.halt(); // Remove the gating sequence from the ring buffer ringBuffer.removeGatingSequence(batchEventProcessor.getSequence()); - - } else { - LOGGER.log(System.Logger.Level.ERROR, "Subscriber not found: {0}", handler); } }