Skip to content

Commit

Permalink
node: never re-track an existing server
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Oct 16, 2024
1 parent d71e2dc commit f3b5de6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/server-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class Tracker {
else return sock.remoteAddress + "|" + sock.remotePort;
}

/**
* @param {string} id
* @param {net.Server} s
* @returns {string} sid
*/
trackServer(id, s) {
if (!s) return this.zeroid;
const mapid = this.sid(s);
Expand All @@ -117,11 +122,13 @@ class Tracker {
const cmap = this.connmap[mapid];
if (cmap) {
log.w("trackServer: server already tracked?", id, mapid);
return mapid;
return this.zeroid;
}

log.i("trackServer: new server", id, mapid);
this.connmap[mapid] = new Map();
this.srvs.push(s);
return mapid;
}

*servers() {
Expand Down Expand Up @@ -372,7 +379,12 @@ function trapServerEvents(id, s) {

if (!s) return;

tracker.trackServer(id, s);
const sid = tracker.trackServer(id, s);

if (sid === tracker.zeroid) {
log.w("tcp: may be already tracking server", id);
return;
}

s.on("connection", (/** @type {Socket} */ socket) => {
stats.nofconns += 1;
Expand Down Expand Up @@ -424,9 +436,15 @@ function trapServerEvents(id, s) {
*/
function trapSecureServerEvents(id, s) {
const ioTimeoutMs = envutil.ioTimeoutMs();

if (!s) return;

tracker.trackServer(id, s);
const sid = tracker.trackServer(id, s);

if (sid === tracker.zeroid) {
log.w("tls: may be already tracking server", id);
return;
}

// github.com/grpc/grpc-node/blob/e6ea6f517epackages/grpc-js/src/server.ts#L392
s.on("secureConnection", (/** @type {TLSSocket} */ socket) => {
Expand Down

0 comments on commit f3b5de6

Please sign in to comment.