mirror of
https://github.com/koush/scrypted.git
synced 2026-03-15 06:32:44 +00:00
server: fix race condition on state reporting
This commit is contained in:
@@ -648,6 +648,10 @@ export function startPluginClusterWorker() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning: do not await in any of these methods unless necessary, otherwise
|
||||
* execution order of state reporting may fail.
|
||||
*/
|
||||
class LazyRemote implements PluginRemote {
|
||||
remote: PluginRemote;
|
||||
|
||||
@@ -658,17 +662,6 @@ class LazyRemote implements PluginRemote {
|
||||
})();
|
||||
}
|
||||
|
||||
async ensureRemote() {
|
||||
try {
|
||||
if (!this.remote)
|
||||
await this.remoteReadyPromise;
|
||||
}
|
||||
catch (e) {
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async loadZip(packageJson: any, zipData: Buffer, options?: PluginRemoteLoadZipOptions): Promise<any> {
|
||||
if (!this.remote)
|
||||
await this.remoteReadyPromise;
|
||||
@@ -685,13 +678,23 @@ class LazyRemote implements PluginRemote {
|
||||
return this.remote.setNativeId(nativeId, id, storage);
|
||||
}
|
||||
async updateDeviceState(id: string, state: { [property: string]: SystemDeviceState; }): Promise<void> {
|
||||
if (!await this.ensureRemote())
|
||||
try {
|
||||
if (!this.remote)
|
||||
await this.remoteReadyPromise;
|
||||
}
|
||||
catch (e) {
|
||||
return;
|
||||
}
|
||||
return this.remote.updateDeviceState(id, state);
|
||||
}
|
||||
async notify(id: string, eventTime: number, eventInterface: string, property: string, propertyState: SystemDeviceState, changed?: boolean): Promise<void> {
|
||||
if (!await this.ensureRemote())
|
||||
try {
|
||||
if (!this.remote)
|
||||
await this.remoteReadyPromise;
|
||||
}
|
||||
catch (e) {
|
||||
return;
|
||||
}
|
||||
return this.remote.notify(id, eventTime, eventInterface, property, propertyState, changed);
|
||||
}
|
||||
async ioEvent(id: string, event: string, message?: any): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user