Skip to content

Commit 671a507

Browse files
committed
fix: Add hard timeout
1 parent e31515c commit 671a507

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

hivemq-edge/src/main/java/com/hivemq/protocols/ProtocolAdapterWrapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@ private void stopAfterFailedStart() {
196196
final AtomicBoolean futureCompleted = new AtomicBoolean(false);
197197
final AtomicBoolean firstCallToStatusListener = new AtomicBoolean(true);
198198
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
199-
final ScheduledFuture<?> scheduledFuture = scheduler.schedule(() -> {
200-
if (futureCompleted.compareAndSet(false, true)) {
199+
final long startTime = System.currentTimeMillis();
200+
final ScheduledFuture<?> scheduledFuture = scheduler.scheduleWithFixedDelay(() -> {
201+
if (((System.currentTimeMillis() - startTime) > (WRITE_FUTURE_COMPLETE_DELAY - 1) * 1000) &&
202+
futureCompleted.compareAndSet(false, true)) {
201203
log.error("Protocol adapter with id {} start writing failed because of timeout.",
202204
adapter.getId());
203205
future.complete(false);
204206
}
205-
}, WRITE_FUTURE_COMPLETE_DELAY, TimeUnit.SECONDS);
207+
}, WRITE_FUTURE_COMPLETE_DELAY, WRITE_FUTURE_COMPLETE_DELAY, TimeUnit.SECONDS);
206208
future.thenAccept(success -> {
207209
if (!scheduledFuture.isCancelled()) {
208210
scheduledFuture.cancel(true);

0 commit comments

Comments
 (0)