[homematic] Fix deadlock on stopping discovery (#20790)

If the scan takes longer than the maximum scan time (120s by default),

Signed-off-by: Danny Baumann <dannybaumann@web.de>
This commit is contained in:
maniac103
2026-05-24 10:10:10 +02:00
committed by GitHub
parent 9c123aebbb
commit 70cd07b552
2 changed files with 16 additions and 12 deletions
@@ -112,14 +112,17 @@ public class HomematicDeviceDiscoveryService
}
@Override
public synchronized void stopScan() {
public void stopScan() {
logger.debug("Stopping Homematic discovery scan");
disableInstallMode();
final HomematicGateway gateway = thingHandler.getGateway();
if (gateway != null) {
gateway.cancelLoadAllDeviceMetadata();
final HomematicGateway gateway;
synchronized (this) {
disableInstallMode();
gateway = thingHandler.getGateway();
if (gateway != null) {
gateway.cancelLoadAllDeviceMetadata();
}
}
waitForScanFinishing();
waitForScanFinishing(gateway);
super.stopScan();
}
@@ -153,8 +156,11 @@ public class HomematicDeviceDiscoveryService
}
private void waitForLoadDevicesFinished() throws InterruptedException, ExecutionException {
Future<?> loadFuture;
if ((loadFuture = loadDevicesFuture) != null) {
final Future<?> loadFuture;
synchronized (this) {
loadFuture = this.loadDevicesFuture;
}
if (loadFuture != null) {
loadFuture.get();
}
}
@@ -162,7 +168,7 @@ public class HomematicDeviceDiscoveryService
/**
* Waits for the discovery scan to finish and then returns.
*/
public void waitForScanFinishing() {
public void waitForScanFinishing(HomematicGateway gateway) {
logger.debug("Waiting for finishing Homematic device discovery scan");
try {
waitForInstallModeFinished(DISCOVER_TIMEOUT_SECONDS * 1000);
@@ -172,8 +178,6 @@ public class HomematicDeviceDiscoveryService
} catch (Exception ex) {
logger.error("Error waiting for device discovery scan: {}", ex.getMessage(), ex);
}
HomematicBridgeHandler bridgeHandler = thingHandler;
HomematicGateway gateway = bridgeHandler.getGateway();
String gatewayId = gateway != null ? gateway.getId() : "UNKNOWN";
logger.debug("Finished Homematic device discovery scan on gateway '{}'", gatewayId);
}
@@ -121,7 +121,7 @@ public class HomematicBridgeHandler extends BaseBridgeHandler implements Homemat
// scan for already known devices (new devices will not be discovered,
// since installMode==true is only achieved if the bridge is online
discoveryService.startScan(null);
discoveryService.waitForScanFinishing();
discoveryService.waitForScanFinishing(gateway);
updateStatus(ThingStatus.ONLINE);
if (!config.getGatewayInfo().isHomegear()) {