Skip to content

Pool connection leak when SET time_zone fails in connect() #18266

Open

Description

@gsomersbb

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

Acquiring a new connection the MySQL ConnectionManager.connect() issues a SET time_zone statement immediately after the mysql2 library creates the connection (

await promisify(cb => connection.query(`SET time_zone = '${tzOffset}'`, cb))();
).

When using connection pooling, if this query fails with a non-fatal error - for example with ER_OUT_OF_RESOURCES (errno 1041) when the server is under memory pressure, or any other query-level error - Sequelize throws a ConnectionError from the outer catch block without closing or destroying the underlying mysql2 connection. The pool never receives the connection object, so it cannot release or destroy it. Thus the connection is orphaned.

Example full error object below (from RDS Aurora MySQL)

Error: Query declined - system memory is critically low. This action was taken to protect system stability.
      at Packet.asError (/opt/node_modules/mysql2/lib/packets/packet.js:791:17)
      at Query.execute (/opt/node_modules/mysql2/lib/commands/command.js:29:26)
      at Connection.handlePacket (/opt/node_modules/mysql2/lib/base/connection.js:552:34)
      at PacketParser.onPacket (/opt/node_modules/mysql2/lib/base/connection.js:102:12)
      at PacketParser.executeStart (/opt/node_modules/mysql2/lib/packet_parser.js:75:16)
      at TLSSocket.<anonymous> (/opt/node_modules/mysql2/lib/base/connection.js:439:25)
      at TLSSocket.emit (node:events:509:28)
      at TLSSocket.emit (node:domain:489:12)
      at addChunk (node:internal/streams/readable:563:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)
      at Readable.push (node:internal/streams/readable:394:5)
      at TLSWrap.onStreamRead (node:internal/stream_base_commons:189:23) {
    code: 'ER_OUT_OF_RESOURCES',
    errno: 1041,
    sqlState: 'HY000',
    sqlMessage: 'Query declined - system memory is critically low. This action was taken to protect system stability.',
    sql: "SET time_zone = '+00:00'"

Reproducible Example

Here is the link to the SSCCE for this issue: sequelize/sequelize-sscce#301

What do you expect to happen?

The connection should be closed if the pool is never going to receive it

What is actually happening?

the connection is not closed, and the pool is never going to receive it

Environment

  • Sequelize version: 6.37.8
  • Node.js version: 22.14.0
  • If TypeScript related: TypeScript version:
  • Database & Version: MySQL 8.4.7
  • Connector library & Version: mysql2 3.22.5

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

Activity

  1. added theissue type on Jul 17, 2026
  2. added
    pending-approval
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-approval

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions