Skip to content

Memory leak due to connection not authenticating, exhausting connection pool #15785

@GalacticHypernova

Description

@GalacticHypernova

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

v9.0.0

Node.js version

v22.17.1

MongoDB server version

8.0.16

Typescript version (if applicable)

Latest

Description

Mongoose generates a lot of connection-related messages in mongodb log file, and spiking RAM usage:

{"t":{"$date":"2025-11-22T14:42:56.745+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn400","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39710","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:56.817+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39726","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"8a045039-0b94-43f1-86ff-746b2bd4418d"}},"connectionId":401,"connectionCount":170}}
{"t":{"$date":"2025-11-22T14:42:56.820+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn401","msg":"client metadata","attr":{"remote":"127.0.0.1:39726","client":"conn401","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:56.820+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn401","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39726","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:58.105+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39730","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"a59a4994-78de-4625-afc0-2f11f8b74cdd"}},"connectionId":402,"connectionCount":171}}
{"t":{"$date":"2025-11-22T14:42:58.105+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn402","msg":"client metadata","attr":{"remote":"127.0.0.1:39730","client":"conn402","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:58.105+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn402","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39730","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:58.236+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39738","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"55627a9b-8ca8-49b2-9c79-a5e3ea7db85d"}},"connectionId":403,"connectionCount":172}}
{"t":{"$date":"2025-11-22T14:42:58.236+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn403","msg":"client metadata","attr":{"remote":"127.0.0.1:39738","client":"conn403","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:58.236+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn403","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39738","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:59.667+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39746","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"d9a71a2d-d9bd-450b-95dd-1940914d2f60"}},"connectionId":404,"connectionCount":173}}
{"t":{"$date":"2025-11-22T14:42:59.667+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn404","msg":"client metadata","attr":{"remote":"127.0.0.1:39746","client":"conn404","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:59.667+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn404","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39746","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:59.678+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39760","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"84a6824c-7b82-400d-95ba-f6174dd098d7"}},"connectionId":405,"connectionCount":174}}
{"t":{"$date":"2025-11-22T14:42:59.679+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn405","msg":"client metadata","attr":{"remote":"127.0.0.1:39760","client":"conn405","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:42:59.679+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn405","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39760","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:01.017+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39772","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"8a725e2d-f220-47ec-99ec-188d1538fcf1"}},"connectionId":406,"connectionCount":175}}
{"t":{"$date":"2025-11-22T14:43:01.018+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn406","msg":"client metadata","attr":{"remote":"127.0.0.1:39772","client":"conn406","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:01.018+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn406","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39772","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:01.174+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:39776","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"956eb07d-54c8-4d05-afd5-b0ddba1b0e38"}},"connectionId":407,"connectionCount":176}}
{"t":{"$date":"2025-11-22T14:43:01.175+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn407","msg":"client metadata","attr":{"remote":"127.0.0.1:39776","client":"conn407","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:01.175+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn407","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:39776","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:02.471+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:41002","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"ddaf6cfd-82ef-478e-b600-ce546a63d81f"}},"connectionId":408,"connectionCount":177}}
{"t":{"$date":"2025-11-22T14:43:02.471+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn408","msg":"client metadata","attr":{"remote":"127.0.0.1:41002","client":"conn408","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:02.471+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn408","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:41002","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:02.664+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:41010","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"b348f820-4026-427c-920c-0800dd07d855"}},"connectionId":409,"connectionCount":178}}
{"t":{"$date":"2025-11-22T14:43:02.664+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn409","msg":"client metadata","attr":{"remote":"127.0.0.1:41010","client":"conn409","negotiatedCompressors":[],"doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}
{"t":{"$date":"2025-11-22T14:43:02.665+00:00"},"s":"I",  "c":"ACCESS",   "id":10483900,"ctx":"conn409","msg":"Connection not authenticating","attr":{"client":"127.0.0.1:41010","doc":{"driver":{"name":"nodejs|Mongoose","version":"7.0.0|9.0.0"},"platform":"Node.js v22.17.1, LE","os":{"name":"linux","architecture":"x64","version":"6.8.0-87-generic","type":"Linux"}}}}

Additionally, here is the result of adminCommand.connections:

{
  current: 242,
  available: 25358,
  totalCreated: 285,
  rejected: 0,
  active: 23,
  queuedForEstablishment: Long('0'),
  establishmentRateLimit: {
    rejected: Long('0'),
    exempted: Long('0'),
    interruptedDueToClientDisconnect: Long('0')
  },
  threaded: 242,
  exhaustIsMaster: Long('0'),
  exhaustHello: Long('18'),
  awaitingTopologyChanges: Long('19'),
  loadBalanced: Long('0')
}

Steps to Reproduce

I am using mongoose as expected in an application, connecting on server startup and disconnecting on server shutdown

await connect(`mongodb://127.0.0.1:27017/${config.dbName}`)


// ... in shutdown ...
await disconnect()

Note that I'm not using authentication (as this is a local instance)

Expected Behavior

It should not have a problem to connect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions