Can't add new command when connection is in closed state

See original GitHub issue

This happened to me today when i upgrade to 0.14.0. Not sure when the bug was introduced.

Also, i saw this along with the above message: This socket has been ended by the other party

Previously working version seems to be 0.13.0

node 8.9.1, knex 0.14.0, “mysql2”: “1.4.2”

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:44 (15 by maintainers)

github_iconTop GitHub Comments

4reactions
rkaw92commented, Nov 14, 2017

Hi, just today we’ve observed (by placing a few good ol’ console.logs) that the factory.validate function which knex.js provides to generic-pool is never called, which might explain how already-dead connections are still being dispensed from the resource pool. Supposedly, generic-pool will validate resources before dispensing, and if they seem broken, create and dispense a new one (in this case, connection) as a replacement. However, this only happens if the right options are passed to generic-pool: https://github.com/coopernurse/node-pool/blob/master/lib/Pool.js#L222

As seen in the code above, the pool will only actually run the validator function if the option testOnBorrow has been enabled. It is false by default, and knex.js does not seem to override it when creating the pool.

2reactions
Yunoocommented, Nov 16, 2017

@rkaw92 I am testing this workaround since yesterday morning and it seems to work fine. Before that I had to restart API processes at least once a day, otherwise database connection will eventually close without reconnection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't add new command when connection is in closed state
I am using the Amazon EC2 with Ubuntu. I am running the server using the PM2, as pm2 start bin/www --log-date-format "YYYY-MM-DD ...
Read more >
Error: Can't add new command when connection is in closed ...
{ Error: Can't add new command when connection is in closed state at PoolConnection._addCommandClosedState. I use mysql 2 and connect Pool.
Read more >
Can't add new command when connection is in closed state ...
I had a similar problem and ended up having to put the connection request in it's own .js file and import it into...
Read more >
Can't add new command when connection is in closed state
Node+Express+MySQLを使ってデータ取得時に2回目から以下のエラーが発生しましたので、原因と解決…
Read more >
connection lost nodejs, node-mysql connection close, can 't ...
can 't add new command when connection is in closed state. I solved my problem by just closing the connection after 10 seconds...
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