Skip to content

Commit

Permalink
Prevent kill of the restarted worker when "exit" event is triggered b…
Browse files Browse the repository at this point in the history
…efore "disconnect"
  • Loading branch information
rmdm committed Dec 27, 2024
1 parent eae4348 commit f4d0730
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/worker_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,13 @@ class WorkerWrapper extends EventEmitterEx {
* @private
*/
_onDisconnect() {
this.ready = false;
this._setState(WorkerWrapper.STATES.STOPPING);
// "disconnect" and "exit" may be triggered in any order:
// https://nodejs.org/docs/latest-v22.x/api/cluster.html#clusterworkers
// Check state is stoppable for coordination.
if (this.isRunning()) {
this.ready = false;
this._setState(WorkerWrapper.STATES.STOPPING);
}
}

/**
Expand Down

0 comments on commit f4d0730

Please sign in to comment.