Skip to content

Commit 9ae54e5

Browse files
committed
remove race condition on stop
1 parent 076048a commit 9ae54e5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

modules/hivemq-edge-module-modbus/src/main/java/com/hivemq/edge/adapters/modbus/ModbusProtocolAdapter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void start(
139139

140140
@Override
141141
public void stop(final @NotNull ProtocolAdapterStopInput input, final @NotNull ProtocolAdapterStopOutput output) {
142-
if (startRequested.get() && stopRequested.compareAndSet(false, true)) {
142+
if (stopRequested.compareAndSet(false, true)) {
143143
log.info("Stopping Modbus protocol adapter {}", adapterId);
144144
publishChangedDataOnlyHandler.clear();
145145
try {
@@ -166,6 +166,12 @@ public void stop(final @NotNull ProtocolAdapterStopInput input, final @NotNull P
166166
} catch (final InterruptedException | ExecutionException e) {
167167
log.error("Unable to stop the connection to the Modbus server", e);
168168
}
169+
} else {
170+
// stop() called when already stopped or stop in progress
171+
// This can happen when stopping after a failed start
172+
// Just complete successfully - adapter is already stopped
173+
log.debug("Stop called for Modbus adapter {} but adapter is already stopped or stopping", adapterId);
174+
output.stoppedSuccessfully();
169175
}
170176
}
171177

0 commit comments

Comments
 (0)