Skip to content

Commit

Permalink
Bump package.json version to 1.8.6 and enhance process termination ha…
Browse files Browse the repository at this point in the history
…ndling in Child and Worker classes
  • Loading branch information
Digital39999 committed Nov 17, 2024
1 parent e6f530d commit 6e1aaa5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.5",
"version": "1.8.6",
"name": "status-sharding",
"author": "Digital39999",
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions src/classes/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,20 @@ export class Child {
return false;
}

this.process.removeAllListeners?.();
try {
this.process.kill();

return new Promise((resolve, reject) => {
this.process?.once('exit', () => resolve(true));
this.process?.once('exit', () => {
this.process?.removeAllListeners?.();
resolve(true);
});

this.process?.once('error', (err) => {
console.error('Error with child process:', err);
reject(err);
});
});
return true;
} catch (error) {
console.error('Child termination failed:', error);
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export class Worker {
return false;
}

this.process.removeAllListeners?.();
try {
this.process!.terminate();

return new Promise((resolve, reject) => {
this.process?.once('exit', () => resolve(true));
this.process?.once('exit', () => {
this.process?.removeAllListeners?.();
resolve(true);
});

this.process?.once('error', (err) => {
console.error('Error with worker thread:', err);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ export class HeartbeatManager {
} as BaseMessage<'heartbeat'>)?.catch(() => null);

if (Date.now() - cluster.lastHeartbeatReceived > this.manager.options.heartbeat.timeout) {
this.manager._debug(`Cluster ${cluster.id} has missed a heartbeat. (${this.getClusterStats(cluster.id).missedBeats} missed)`);
this.addMissedBeat(cluster.id);
} else {
const clusterData = this.getClusterStats(cluster.id);
if (clusterData.missedBeats > 0) {
clusterData.missedBeats = 0;
this.beats.set(cluster.id, clusterData);
}

this.manager._debug(`Cluster ${cluster.id} has received a heartbeat.`);
}
}
}, this.manager.options.heartbeat.interval);
Expand Down

0 comments on commit 6e1aaa5

Please sign in to comment.