From f27a6c35017e4eb37546949f754e09933102837a Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 9 Nov 2023 11:41:13 +0100 Subject: [PATCH] refactor: remove useless reference A reference to the initial IncomingMessage object (the first HTTP request of the session) is kept in memory by default (`socket.request`), so its attached ServerResponse object (`req.res`) would not be garbage-collected. This will now be the case. Note: the IncomingMessage object is needed in two cases: - when working with the `express-session` middleware (`request.session`) - when fetching the certificate of the client with `request.socket.getPeerCertificate()` That's why removing it would be a breaking change. --- lib/transports-uws/polling.ts | 2 ++ lib/transports/polling.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/transports-uws/polling.ts b/lib/transports-uws/polling.ts index 4ce6e52f..16e72c00 100644 --- a/lib/transports-uws/polling.ts +++ b/lib/transports-uws/polling.ts @@ -55,6 +55,8 @@ export class Polling extends Transport { */ onRequest(req) { const res = req.res; + // remove the reference to the ServerResponse object (as the first request of the session is kept in memory by default) + req.res = null; if (req.getMethod() === "get") { this.onPollRequest(req, res); diff --git a/lib/transports/polling.ts b/lib/transports/polling.ts index f0edcdc8..e5ea24cf 100644 --- a/lib/transports/polling.ts +++ b/lib/transports/polling.ts @@ -54,6 +54,8 @@ export class Polling extends Transport { */ onRequest(req: IncomingMessage & { res: ServerResponse }) { const res = req.res; + // remove the reference to the ServerResponse object (as the first request of the session is kept in memory by default) + req.res = null; if ("GET" === req.method) { this.onPollRequest(req, res);