sidorares / sidorares/node-mysql2
Connection state is not reset on return to pool
@sidorares is already working on this.
Since Apr 10, 2026.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
Per comment on https://github.com/sidorares/node-mysql2/issues/925#issuecomment-471101203
This library does not reset the state of a connection returned to the pool before it is reused.
This means if any operation mutates state of the connection such as session level variables/isolation level, or begins a transaction without committing or rolling back, the new connection request is given a dirty connection object.
This can lead to rather extreme bugs.
to resolve this, the library needs to follow the industry standard practice of issuing a connection.changeUser() with the same user the connection was opened with, ensuring that the state is all reset.
I would suggest doing this on connection release rather than connection acquire so that obtaining a connection can be faster.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.