node-mysql2: node-mysql2 hangs for long time without showing anything
I have a script, that makes heavy use of node-mysql2. It inserts large number of rows into db, then proceeds to make further modifications to those rows. First part is run as separate promise with lots of async/await.
After the first part, during the early stages of second part script suddenly hangs (at first I attributed that to some kind of terminal IO glitch, but the behaviour is reproducible in different terminals both on Windows and Linux). mysql processlist looks like this
+-----+------+-----------+------+---------+------+-------+-----------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+-----+------+-----------+------+---------+------+-------+-----------------------+----------+
| 130 | root | localhost | basa | Sleep | 1 | | NULL | 0.000 |
| 133 | root | localhost | NULL | Query | 0 | init | SHOW FULL PROCESSLIST | 0.000 |
+-----+------+-----------+------+---------+------+-------+-----------------------+----------+
Interestingly, running the first and second part of script separately eliminates the issue.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 2
- Comments: 24 (12 by maintainers)
Hello, I will create a very isolated example replicating my problem,
@jacobbogers based on the previous comments, did you also use fire many without awaiting one by one, and then await Promise.all approach? Anyone doing that, then you really need to fix that and do something like
for (const blah of array) { await conn.execute(sql, params); }
there is no benefit to Promise.all unless every request also obtains a connection from the pool so they use up the entire pool. A single connection needs to be awaited one by one.
This is horrible, I having the EXACT same issue with bulk inserts (not even alot like 1-10 rows at a time for a single table) This is cleary not a mysql DB issue, yes I do see. regardless if i wrap the whole thing into a START TRANSACTION… COMMIT.
Through debugging I see the command queue growing, and growing but never finishing previous commands.