Skip to content

Possible EventEmitter memory leak when used together with MongoDBContainer (Testcontainers) #2830

@Jualex

Description

@Jualex

Please avoid duplicates

Reproducible test case

https://runkit.com/jualex/6798feda0e8102000908a12a

Nock Version

14.0.0

Node Version

20.18.1

TypeScript Version

TypeScript 5.7.3

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "./dist",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "sourceMap": true,
    "pretty": true,
    "allowJs": false,
    "strict": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "types": ["jest"],
    "lib": ["esnext"],
    "importHelpers": true,
    "resolveJsonModule": true,
    "noUncheckedIndexedAccess": true
  },
  "include": ["src/**/*", "tests/**/*"],
  "exclude": ["node_modules", "tests/cli/**/*"]
}

What happened?

After updating nock from 13.5.6 to 14.0.0, we get the following warning in our Jest tests where both nock and @testcontainers/mongodb (10.17.2) is used, every time a new MongoDBContainer is started.

(node:10063) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added to [MockHttpSocket]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit

Additionally, sometimes there are active handles left after the test causing the test to time out unless --forceExit is used. It is not clear whether this is related to the warning, but it is our suspicion.

From a initial debugging session, the warning seems to come from the code where the MongoDB testcontainer uses a Unix domain socket to stream the logs of the MongoDB container to check if it has started up.

Would you be interested in contributing a fix?

  • yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions