Skip to content

Commit

Permalink
refactor: remove useless reference
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
darrachequesne committed Nov 9, 2023
1 parent 2da559a commit f27a6c3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/transports-uws/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions lib/transports/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f27a6c3

Please sign in to comment.