sidorares / sidorares/node-mysql2
Statement unprepare crash
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
I'm getting the following crashes for around 5% of requests with higher concurrency:
TypeError: Cannot call method 'execute' of undefined
at PoolConnection.Connection.handlePacket (/opt/api-devel/node_modules/mysql2/lib/connection.js:297:28)
at PacketParser.onPacket (/opt/api-devel/node_modules/mysql2/lib/connection.js:83:65)
at PacketParser.executeStart (/opt/api-devel/node_modules/mysql2/lib/packet_parser.js:39:12)
at Socket.<anonymous> (/opt/api-devel/node_modules/mysql2/lib/connection.js:95:31)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:748:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:410:10)
at emitReadable (_stream_readable.js:406:5)
at readableAddChunk (_stream_readable.js:168:9)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:528:21)
For some reason I can't reproduce it on my local machine but it happens on the development servers which are connected to a Percona cluster.
Basically I'm creating a prepared statement for a query that uses an IN clause, and since these are not very cacheable I'd like to immediately close them (in the callback). That's when the crashes happen.
Tried using execute/unprepare and prepare/execute/close but both seem to have the same issue.
I thought this might be due to unpreparing a statement before it gets executed by a different request, but shouldn't the statements be separate especially in the prepare/execute/close case?
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 with lib/connection.js around line 297 and the packet flow through lib/packet_parser.js, then trace the prepared-statement prepare/execute/unprepare and prepare/execute/close paths under concurrent requests. Reproduce against a Percona cluster if possible; done means concurrent statement cleanup no longer calls execute on an undefined statement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100