node-mysql2 hangs for long time without showing anything
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:24 (12 by maintainers)
Top Results From Across the Web
node.js - NodeJS Server with mysql hangs - Stack Overflow
MySQL does indeed prune idle connections. There's a MySQL variable "wait_timeout" that sets the number of second before timeout and the default ...
Read more >The Node.js MySQL Driver Doesn't .end() As Gracefully With ...
js process will hang without it (until the MySQL database drops the connections). As I discovered, however, the .end() method in the connection ......
Read more >Node.js ORMs: Why you shouldn't use them - LogRocket Blog
ORM is a powerful tool, but it adds a layer of complexity that can cause some hiccups. Here's why you may want to...
Read more >Best Practices for Node.js Error-handling - Toptal
The best way to deal with these errors is to crash immediately and restart gracefully with an automatic restarter like PM2—the reason being...
Read more >This is why your Node.js application is slow
The important question then is “while we wait for the promise to get fulfilled, is it ideal to “idly” wait and not execute...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.