Skip to content

Commit f4d0730

Browse files
committed
Prevent kill of the restarted worker when "exit" event is triggered before "disconnect"
1 parent eae4348 commit f4d0730

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/worker_wrapper.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ class WorkerWrapper extends EventEmitterEx {
250250
* @private
251251
*/
252252
_onDisconnect() {
253-
this.ready = false;
254-
this._setState(WorkerWrapper.STATES.STOPPING);
253+
// "disconnect" and "exit" may be triggered in any order:
254+
// https://nodejs.org/docs/latest-v22.x/api/cluster.html#clusterworkers
255+
// Check state is stoppable for coordination.
256+
if (this.isRunning()) {
257+
this.ready = false;
258+
this._setState(WorkerWrapper.STATES.STOPPING);
259+
}
255260
}
256261

257262
/**

0 commit comments

Comments
 (0)