mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
Handle process crashes slightly more gracefully
This commit is contained in:
parent
28625d9efd
commit
4e9ad4e373
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user