question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

node-mysql2 hangs for long time without showing anything

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:24 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
jacobbogerscommented, Dec 2, 2019

Hello, I will create a very isolated example replicating my problem,

1reaction
aikarcommented, Dec 4, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found