From 21755013b69570790fcf987fdd476f3da815be0b Mon Sep 17 00:00:00 2001 From: roeschter Date: Fri, 15 Nov 2024 20:50:37 +0100 Subject: [PATCH] Fix: exception on simple consume when disconnected immediately (#1253) --- .../nats/client/impl/NatsMessageConsumer.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/nats/client/impl/NatsMessageConsumer.java b/src/main/java/io/nats/client/impl/NatsMessageConsumer.java index aa7987631..8e4f7a125 100644 --- a/src/main/java/io/nats/client/impl/NatsMessageConsumer.java +++ b/src/main/java/io/nats/client/impl/NatsMessageConsumer.java @@ -58,7 +58,8 @@ public void heartbeatError() { doSub(); } catch (JetStreamApiException | IOException e) { - setupHbAlarmToTrigger(); + pmm.resetTracking(); + pmm.initOrResetHeartbeatTimer(); } } @@ -69,20 +70,10 @@ void doSub() throws JetStreamApiException, IOException { finished.set(true); } }; - try { - super.initSub(subscriptionMaker.subscribe(mh, userDispatcher, pmm, null)); - repull(); - stopped.set(false); - finished.set(false); - } - catch (JetStreamApiException | IOException e) { - setupHbAlarmToTrigger(); - } - } - - private void setupHbAlarmToTrigger() { - pmm.resetTracking(); - pmm.initOrResetHeartbeatTimer(); + super.initSub(subscriptionMaker.subscribe(mh, userDispatcher, pmm, null)); + repull(); + stopped.set(false); + finished.set(false); } @Override