Skip to content

Commit c32ff8a

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

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

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

Lines changed: 14 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,9 @@ 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("[%s] sending response %s to %s", this.uid, response.type, requesterUid);
714+
702715
this.doPublishResponse(requesterUid, response as ClusterResponse).catch(
703716
(err) => {
704717
debug("[%s] error while publishing response: %s", this.uid, err);
@@ -790,17 +803,10 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter {
790803
}
791804

792805
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
806+
// we track the UID of each sender to know how many servers there are in the cluster
794807
this.nodesMap.set(message.uid, Date.now());
795808
}
796809

797-
debug(
798-
"[%s] new event of type %d from %s",
799-
this.uid,
800-
message.type,
801-
message.uid,
802-
);
803-
804810
switch (message.type) {
805811
case MessageType.INITIAL_HEARTBEAT:
806812
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)