diff --git a/src/controller/Shard.js b/src/controller/Shard.js index d462c7a..a4e0c5e 100644 --- a/src/controller/Shard.js +++ b/src/controller/Shard.js @@ -38,7 +38,7 @@ class Shard extends EventEmitter { this.process = ChildProcess.fork(this.filePath, this.args, { env: { ...this.env, SHARD_ID: this.id }, execArgv: this.execArgv }) .on('message', this._handleMessage.bind(this)) - .on('exit', this._handleExit().bind(this)) + .on('exit', this._handleExit.bind(this)) .on('disconnect', this._handleDisconnect.bind(this)); // Don't know if this is going to help, but monitoring whether this gets called whenever a process on its own closes the IPC channel this.process.once('spawn', () => { @@ -136,7 +136,7 @@ class Shard extends EventEmitter { } _handleExit (code, signal, respawn = this._respawn) { - this.process.removeAllListeners(); + if (this.process) this.process.removeAllListeners(); this.emit('death'); if (code !== 0) this.crashes.push(Date.now() - this.spawnedAt);