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.

Database connection is not correctly destroyed after knex 0.12.2

See original GitHub issue

Hey 👋

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:closed
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
wubzzcommented, Mar 15, 2017

Based on the changelog I would guess #1731 causes this in some way. Some changes to acquireConnection was 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.

const db = require('knex')({...});

db
.transaction((tr) => tr('user').select())
.then(() => db.destroy())
.then(() => console.log('Destroyed'));
//No open connections in server status
1reaction
wubzzcommented, Mar 15, 2017

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

Read more comments on GitHub >

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

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