Database connection is not correctly destroyed after knex 0.12.2
See original GitHub issueHey 👋
I have recently updated knex from 0.12.2 to 0.12.7 and noticed that the database connection is not closed when calling connection.destroy. The result is, that a process doesn’t exit.
Here is a snippet:
....
this.connection = knex(...);
return this.connection.transaction(function(txn) {
return doSomething(txn)
.finally(function() {
return self.connection.destroy()
.then(function () {
debug('Destroyed connection');
});
});
})
NOTE: debug(‘Destroyed connection’) get’s called.
I have tested all knex versions and it starts in 0.12.3.
The code works for me with 0.12.2, but does not with 0.12.3.
Is there anything i can change in my code to get it working with > 0.12.2?
Otherwise, I went through the changes, maybe related to the pool update https://github.com/tgriesser/knex/pull/1702?
Thank you so much! Kate
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Changelog - Knex.js
Fix support for Oracle connections passed via knex.connection() #4757 ... Ensure DB stream is destroyed when the PassThrough is destroyed #2324 ...
Read more >where to destroy knex connection - node.js - Stack Overflow
Knex destroy () seems to be a one time operation. After destroying a connection, one might require a brand new connection pool for...
Read more >Bookshelf.js | Home
The issue here is that Knex, the database abstraction layer used by Bookshelf, uses connection pooling and thus keeps the database connection open....
Read more >CHANGELOG.md
Ensure knex.destroy() returns a bluebird promise #2589 - Increment floats #2614 ... Fix connection error propagation when streaming #2199 - Fix comments not...
Read more >Vincit/objection.js - Gitter
There's a way to do that, but it's not part of the publich API (yet anyway) ... I do clear my DB &...
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

Based on the changelog I would guess #1731 causes this in some way. Some changes to
acquireConnectionwas done so that connections are properly returned to the pool.Edit: Testing with postgres, I’m unable to reproduce the issue as described, while switching between versions 0.12.2 -> 0.12.7. Viewing the PG server status, the connections appear to close properly and returns to the pool in both versions. The process does not exit in either version.
@kirrg001 I see, I thought your app remained idle eventhough all attempts of acquiring connections were successful, but I understand now that’s not the case.
I’ll merge this in right now, definitely a bug. Thanks for the report!