Skip to content

MockHttpSocket and MockHttpAgent are not being garbage collected #2405

@rossipedia

Description

@rossipedia

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

22.12.0

Reproduction repository

https://github.com/rossipedia/msw-leak-test

Reproduction steps

Instructions are in the reproduction repo, but they are essentially:

  1. clone repro
  2. npm install
  3. ./demo.sh

Current behavior

Note

This is a follow up to my colleague's issue #2390

Enabling MSW with no handlers and then load-testing using ab causes heap usage to balloon, even when manually invoking garbage collection.

As best I can tell, the largest percentage of retained objects are primarily:

  • MockHttpSocket
  • MockHttpAgent

I do not believe this is related to express, as only ClientRequest is intercepted, and I don't think express or http.createServer use ClientRequest, only IncomingMessage and ServerResponse (I could be wrong about that though).

Expected behavior

Memory usage should be stable under load when simply enabling MSW in a node application.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededneeds:triageIssues that have not been investigated yet.scope:nodeRelated to MSW running in Node

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions