Merge pull request #871 from shocknet/handle-child-signal

handle exit signal when code is null
This commit is contained in:
Justin (shocknet) 2026-01-28 11:02:53 -05:00 committed by GitHub
commit e15668b442
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 17 deletions

View file

@ -18,12 +18,12 @@ export default class NostrSubprocess {
this.log(ERROR, "nostr subprocess error", error) this.log(ERROR, "nostr subprocess error", error)
}) })
this.childProcess.on("exit", (code) => { this.childProcess.on("exit", (code, signal) => {
this.log(ERROR, `nostr subprocess exited with code ${code}`) this.log(ERROR, `nostr subprocess exited with code ${code} and signal ${signal}`)
if (!code) { if (code === 0) {
return return
} }
throw new Error(`nostr subprocess exited with code ${code}`) throw new Error(`nostr subprocess exited with code ${code} and signal ${signal}`)
}) })
this.childProcess.on("message", (message: ChildProcessResponse) => { this.childProcess.on("message", (message: ChildProcessResponse) => {
@ -69,6 +69,6 @@ export default class NostrSubprocess {
this.sendToChildProcess({ type: 'send', data, initiator, relays }) this.sendToChildProcess({ type: 'send', data, initiator, relays })
} }
Stop() { Stop() {
this.childProcess.kill() this.childProcess.kill(0)
} }
} }

View file

@ -29,7 +29,7 @@ export class StorageInterface extends EventEmitter {
private debug: boolean = false; private debug: boolean = false;
private utils: Utils private utils: Utils
private dbType: 'main' | 'metrics' private dbType: 'main' | 'metrics'
private log = getLogger({component: 'StorageInterface'}) private log = getLogger({ component: 'StorageInterface' })
constructor(utils: Utils) { constructor(utils: Utils) {
super(); super();
this.initializeSubprocess(); this.initializeSubprocess();
@ -61,13 +61,13 @@ export class StorageInterface extends EventEmitter {
this.isConnected = false; this.isConnected = false;
}); });
this.process.on('exit', (code: number) => { this.process.on('exit', (code: number, signal: string) => {
this.log(ERROR, `Storage processor exited with code ${code}`); this.log(ERROR, `Storage processor exited with code ${code} and signal ${signal}`);
this.isConnected = false; this.isConnected = false;
if (!code) { if (code === 0) {
return return
} }
throw new Error(`Storage processor exited with code ${code}`) throw new Error(`Storage processor exited with code ${code} and signal ${signal}`)
}); });
this.isConnected = true; this.isConnected = true;
@ -179,7 +179,7 @@ export class StorageInterface extends EventEmitter {
reject(new Error('Invalid storage response type')); reject(new Error('Invalid storage response type'));
return return
} }
resolve(deserializeResponseData(response.data)); resolve(deserializeResponseData(response.data));
} }
this.once(op.opId, responseHandler) this.once(op.opId, responseHandler)
this.process.send(this.serializeOperation(op)) this.process.send(this.serializeOperation(op))
@ -205,7 +205,7 @@ export class StorageInterface extends EventEmitter {
public disconnect() { public disconnect() {
if (this.process) { if (this.process) {
this.process.kill(); this.process.kill(0);
this.isConnected = false; this.isConnected = false;
this.debug = false; this.debug = false;
} }

View file

@ -53,13 +53,13 @@ export class TlvStorageFactory extends EventEmitter {
this.isConnected = false; this.isConnected = false;
}); });
this.process.on('exit', (code: number) => { this.process.on('exit', (code: number, signal: string) => {
this.log(ERROR, `Tlv Storage processor exited with code ${code}`); this.log(ERROR, `Tlv Storage processor exited with code ${code} and signal ${signal}`);
this.isConnected = false; this.isConnected = false;
if (!code) { if (code === 0) {
return return
} }
throw new Error(`Tlv Storage processor exited with code ${code}`) throw new Error(`Tlv Storage processor exited with code ${code} and signal ${signal}`)
}); });
this.isConnected = true; this.isConnected = true;
@ -173,7 +173,7 @@ export class TlvStorageFactory extends EventEmitter {
public disconnect() { public disconnect() {
if (this.process) { if (this.process) {
this.process.kill(); this.process.kill(0);
this.isConnected = false; this.isConnected = false;
this.debug = false; this.debug = false;
} }