Skip to content

Commit

Permalink
fix: properly handle ERR_IPC_CHANNEL_CLOSED errors (#6)
Browse files Browse the repository at this point in the history
Related: #5
  • Loading branch information
RolandoAndrade authored and darrachequesne committed Oct 13, 2022
1 parent 43f9ee8 commit be0a0e3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface ClusterAdapterOptions {
requestsTimeout: number;
}

function ignoreError() {}

/**
* Returns a function that will create a ClusterAdapter instance.
*
Expand Down Expand Up @@ -295,7 +297,7 @@ export class ClusterAdapter extends Adapter {
message.nsp
);

process.send(message);
process.send(message, null, { swallowErrors: true }, ignoreError);
}

/**
Expand Down Expand Up @@ -559,7 +561,7 @@ export function setupPrimary() {
const workerId = message.data.workerId;
// emit back to the requester
if (hasOwnProperty.call(cluster.workers, workerId)) {
cluster.workers[workerId].send(message);
cluster.workers[workerId].send(message, null, ignoreError);
}
break;
default:
Expand All @@ -570,7 +572,7 @@ export function setupPrimary() {
hasOwnProperty.call(cluster.workers, workerId) &&
workerId !== emitterIdAsString
) {
cluster.workers[workerId].send(message);
cluster.workers[workerId].send(message, null, ignoreError);
}
}
}
Expand All @@ -580,11 +582,15 @@ export function setupPrimary() {
// notify all active workers
for (const workerId in cluster.workers) {
if (hasOwnProperty.call(cluster.workers, workerId)) {
cluster.workers[workerId].send({
source: MESSAGE_SOURCE,
type: EventType.WORKER_EXIT,
data: worker.id,
});
cluster.workers[workerId].send(
{
source: MESSAGE_SOURCE,
type: EventType.WORKER_EXIT,
data: worker.id,
},
null,
ignoreError
);
}
}
});
Expand Down

0 comments on commit be0a0e3

Please sign in to comment.