sidorares / sidorares/node-mysql2
Feature request: getConnection timeout
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
I ran into a problem where a service caused a deadlock by waiting on getConnection. Here is a rough example of the code:
await pool.withTransaction(async tx => {
await service.prepare()
await doSomething(tx)
})
Many long-running requests caused the pool to saturate, then the service caused a deadlock and kept the transaction open. This is easily fixed by not giving service the pool, or by checking that we aren't already in a transaction.
However, a timeout could be useful to avoid these unexpected situations:
// 5s timeout on getConnection
const pool = createPool({ acquireTimeout: 5_000 });
// and/or
await pool.getConnection({ timeout: 1_000 })
// or with signals
await pool.getConnection({ signal: AbortSignal.timeout(1_000) })
A timeout can be implemented by users, but they can't remove the request from the queue on timeout. There is also a gotcha that leaks connections if not implemented correctly. So, I think this should be a library feature.
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.
Research direction
Start at the pool's getConnection acquisition path and review how queued requests and connections are handled. Compare the proposed pool-level acquireTimeout, per-call timeout, and AbortSignal options, then define which behavior should be supported. Done means timed-out requests leave the queue safely without leaking connections, with tests covering the timeout cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js, typescript
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100