Skip to content

Commit 693080c

Browse files
refactor(sio-adapter): add more debug logs
1 parent 5080c73 commit 693080c

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

packages/socket.io-adapter/lib/cluster-adapter.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ export abstract class ClusterAdapter extends Adapter {
199199
return debug("[%s] ignore message from self", this.uid);
200200
}
201201

202+
if (message.nsp !== this.nsp.name) {
203+
return debug(
204+
"[%s] ignore message from another namespace (%s)",
205+
this.uid,
206+
message.nsp,
207+
);
208+
}
209+
202210
debug(
203211
"[%s] new event of type %d from %s",
204212
this.uid,
@@ -671,6 +679,8 @@ export abstract class ClusterAdapter extends Adapter {
671679
protected publish(
672680
message: DistributiveOmit<ClusterMessage, "nsp" | "uid">,
673681
): void {
682+
debug("[%s] sending message %s", this.uid, message.type);
683+
674684
this.publishAndReturnOffset(message).catch((err) => {
675685
debug("[%s] error while publishing message: %s", this.uid, err);
676686
});
@@ -699,6 +709,14 @@ export abstract class ClusterAdapter extends Adapter {
699709
) {
700710
(response as ClusterResponse).uid = this.uid;
701711
(response as ClusterResponse).nsp = this.nsp.name;
712+
713+
debug(
714+
"[%s] sending response %s to %s",
715+
this.uid,
716+
response.type,
717+
requesterUid,
718+
);
719+
702720
this.doPublishResponse(requesterUid, response as ClusterResponse).catch(
703721
(err) => {
704722
debug("[%s] error while publishing response: %s", this.uid, err);
@@ -790,17 +808,10 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter {
790808
}
791809

792810
if (message.uid && message.uid !== EMITTER_UID) {
793-
// we track the UID of each sender, in order to know how many servers there are in the cluster
811+
// we track the UID of each sender to know how many servers there are in the cluster
794812
this.nodesMap.set(message.uid, Date.now());
795813
}
796814

797-
debug(
798-
"[%s] new event of type %d from %s",
799-
this.uid,
800-
message.type,
801-
message.uid,
802-
);
803-
804815
switch (message.type) {
805816
case MessageType.INITIAL_HEARTBEAT:
806817
this.publish({

packages/socket.io-adapter/test/cluster-adapter.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ describe("cluster adapter", () => {
6767
serverSockets.push(socket);
6868
servers.push(io);
6969
if (servers.length === NODES_COUNT) {
70-
// ensure all nodes know each other
71-
servers[0].emit("ping");
72-
servers[1].emit("ping");
73-
servers[2].emit("ping");
74-
7570
done();
7671
}
7772
});

0 commit comments

Comments
 (0)