sidorares / sidorares/node-mysql2

Receiving "Connection lost: The server closed the connection." with createPool

Open
#2,247 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

When calling execute or query from a Pool returned from createPool, I'm occasionally getting the error "Connection lost: The server closed the connection.". This error looks like it is coming from a stream close event in connection.js.

My understanding is that Pool should automatically capture this condition and recreate a connection, but that does not appear to be happening (i.e. I don't understand why I would be seeing this error when using Pool.execute or Pool.query. I'm not seeing anything in Pool.getConnection/query/execute that appear to be set up to handle a closed connection. Do I need to write my own error handling around this?

As context, I'm using this from Lambda to connect to RDSProxy, so that makes it even more fun to diagnose :)

Thanks

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in connection.js at the stream close event, then trace Pool.getConnection, Pool.query, and Pool.execute to see how closed connections are handled. Reproduce the failure if possible in the Lambda/RDSProxy context and define done as Pool operations recovering from a closed connection without exposing the connection-lost error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, mysql, nodejs
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.