fix: Fix crash due to race condition during interview (#21680)

Fixes #21118
Mentioned in #21036 and #20688

Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
Simon Rettberg
2024-03-05 21:28:35 +01:00
committed by GitHub
co-authored by Koen Kanters
parent e2fa66a38c
commit 2da80954d6
+2 -2
View File
@@ -88,16 +88,16 @@ export default class Zigbee {
});
this.herdsman.on('deviceInterview', async (data: ZHEvents.DeviceInterviewPayload) => {
const device = this.resolveDevice(data.device.ieeeAddr);
await device.resolveDefinition();
/* istanbul ignore if */ if (!device) return; // Prevent potential race
await device.resolveDefinition();
const d = {device, status: data.status};
this.logDeviceInterview(d);
this.eventBus.emitDeviceInterview(d);
});
this.herdsman.on('deviceJoined', async (data: ZHEvents.DeviceJoinedPayload) => {
const device = this.resolveDevice(data.device.ieeeAddr);
await device.resolveDefinition();
/* istanbul ignore if */ if (!device) return; // Prevent potential race
await device.resolveDefinition();
logger.info(`Device '${device.name}' joined`);
this.eventBus.emitDeviceJoined({device});
});