Skip to content

Commit be0a0e3

Browse files
RolandoAndradedarrachequesne
authored andcommitted
fix: properly handle ERR_IPC_CHANNEL_CLOSED errors (#6)
Related: socketio/socket.io-cluster-adapter#5
1 parent 43f9ee8 commit be0a0e3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export interface ClusterAdapterOptions {
5151
requestsTimeout: number;
5252
}
5353

54+
function ignoreError() {}
55+
5456
/**
5557
* Returns a function that will create a ClusterAdapter instance.
5658
*
@@ -295,7 +297,7 @@ export class ClusterAdapter extends Adapter {
295297
message.nsp
296298
);
297299

298-
process.send(message);
300+
process.send(message, null, { swallowErrors: true }, ignoreError);
299301
}
300302

301303
/**
@@ -559,7 +561,7 @@ export function setupPrimary() {
559561
const workerId = message.data.workerId;
560562
// emit back to the requester
561563
if (hasOwnProperty.call(cluster.workers, workerId)) {
562-
cluster.workers[workerId].send(message);
564+
cluster.workers[workerId].send(message, null, ignoreError);
563565
}
564566
break;
565567
default:
@@ -570,7 +572,7 @@ export function setupPrimary() {
570572
hasOwnProperty.call(cluster.workers, workerId) &&
571573
workerId !== emitterIdAsString
572574
) {
573-
cluster.workers[workerId].send(message);
575+
cluster.workers[workerId].send(message, null, ignoreError);
574576
}
575577
}
576578
}
@@ -580,11 +582,15 @@ export function setupPrimary() {
580582
// notify all active workers
581583
for (const workerId in cluster.workers) {
582584
if (hasOwnProperty.call(cluster.workers, workerId)) {
583-
cluster.workers[workerId].send({
584-
source: MESSAGE_SOURCE,
585-
type: EventType.WORKER_EXIT,
586-
data: worker.id,
587-
});
585+
cluster.workers[workerId].send(
586+
{
587+
source: MESSAGE_SOURCE,
588+
type: EventType.WORKER_EXIT,
589+
data: worker.id,
590+
},
591+
null,
592+
ignoreError
593+
);
588594
}
589595
}
590596
});

0 commit comments

Comments
 (0)