diff --git a/lib/process-manager.js b/lib/process-manager.js index a608a1fd04..1665f38430 100644 --- a/lib/process-manager.js +++ b/lib/process-manager.js @@ -28,10 +28,12 @@ class SubprocessStream extends Streams.ObjectReadWriteStream { this.process.send(`${taskId}\nNEW`); } _write(/** @type {string} */ message) { + if (!process.connected) return; this.process.send(`${this.taskId}\nWRITE\n${message}`); // responses are handled in ProcessWrapper } _destroy() { + if (!process.connected) return; this.process.send(`${this.taskId}\nDESTROY`); } } @@ -67,6 +69,9 @@ class QueryProcessWrapper { if (this.resolveRelease && !this.load) this.destroy(); }); + this.process.on('disconnect', () => { + this.destroy(); + }); } get load() { diff --git a/room-battle.js b/room-battle.js index f4d0988f2c..949d334ba2 100644 --- a/room-battle.js +++ b/room-battle.js @@ -576,6 +576,13 @@ class Battle { while ((next = await this.stream.read())) { this.receive(next.split('\n')); } + if (!this.ended) { + this.room.add(`|bigerror|The simulator process has crashed. We've been notified and will fix this ASAP.`); + Monitor.crashlog(new Error(`Process disconnected`), `A battle`); + this.started = true; + this.ended = true; + this.checkActive(); + } } receive(/** @type {string[]} */ lines) { switch (lines[0]) { @@ -960,6 +967,7 @@ class Battle { } destroy() { + this.ended = true; this.stream.destroy(); if (this.active) { Rooms.global.battleCount += -1;