This commit is contained in:
Koushik Dutta
2024-04-09 22:19:09 -07:00
parent fb37f9f58d
commit 16d38906fe
5 changed files with 13 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@scrypted/server",
"version": "0.98.0",
"version": "0.98.1",
"description": "",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.11",

View File

@@ -319,10 +319,6 @@ export class PluginHost {
logger.log('e', `${this.pluginName} close`);
disconnect();
});
this.worker.on('disconnect', () => {
logger.log('e', `${this.pluginName} disconnected`);
disconnect();
});
this.worker.on('exit', async (code, signal) => {
logger.log('e', `${this.pluginName} exited ${code} ${signal}`);
disconnect();

View File

@@ -11,10 +11,9 @@ export abstract class ChildProcessWorker extends EventEmitter implements Runtime
}
setupWorker() {
this.worker.on('close', () => this.emit('close'));
this.worker.on('disconnect', () => this.emit('disconnect'));
this.worker.on('close', (code: number | null, signal: NodeJS.Signals | null) => this.emit('close', code, signal));
this.worker.on('disconnect', () => this.emit('error', new Error('disconnect')));
this.worker.on('exit', (code, signal) => this.emit('exit', code, signal));
this.worker.on('close', () => this.emit('close'));
this.worker.on('error', e => this.emit('error', e));
}

View File

@@ -20,11 +20,14 @@ export interface RuntimeWorker {
kill(): void;
on(event: 'rpc', listener: (message: any, sendHandle: net.Socket) => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
on(event: 'disconnect', listener: () => void): this;
on(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
on(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
once(event: 'error', listener: (err: Error) => void): this;
once(event: 'exit', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
once(event: 'close', listener: (code: number | null, signal: NodeJS.Signals | null) => void): this;
send(message: RpcMessage, reject?: (e: Error) => void, serializationContext?: any): void;

View File

@@ -627,7 +627,7 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
}
setupPluginHostAutoRestart(pluginHost: PluginHost) {
pluginHost.worker.once('exit', () => {
const restart = () => {
if (pluginHost.killed)
return;
pluginHost.kill();
@@ -653,7 +653,10 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
console.error('error restarting plugin', plugin._id, e);
}
}, timeout);
});
};
pluginHost.worker.once('error', restart);
pluginHost.worker.once('exit', restart);
pluginHost.worker.once('close', restart);
}
loadPlugin(plugin: Plugin, pluginDebug?: PluginDebug) {