Knex is not clearing timeouts after they have become unnecessary
See original GitHub issueEnvironment
Knex version: 0.20.10 Database + version: postgres 12.1 OS: Linux Node: 12.15.0 Jest: 25.1.0
Bug
Jest prints a warning about open handles when a test creates and rollbacks a transaction. When I comment out transacting code, the warning disappears. The connection to postgres database is closed in afterAll call.
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your
tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
--detectOpenHandles
flag does not detect anything.
Here is the reproduction code:
const Knex = require('knex');
const db = Knex({
client: process.env.DB_TYPE || 'pg',
connection: {
host: process.env.DB_HOST || 'localhost',
port: Number(process.env.DB_PORT) || 5432,
user: process.env.DB_USER || 'postgres',
password: process.env.DB_USER || 'postgres',
database: process.env.DB_DATABASE || 'postgres',
},
});
describe('test', () => {
afterAll(async () => {
await db.destroy();
});
it('transacts', async () => {
const t = await db.transaction();
await t.rollback();
});
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Knex: Timeout acquiring a connection. The pool is probably ...
The solution is to set propagateCreateError to false thus enabling knex to automatically reconnect on create connection failure instead of ...
Read more >Changelog - Knex.js
Fix timeout method #4324; SQLite: prevent dropForeign from being silently ignored #4376. Typings ... CLI: Print help only when there are no arguments...
Read more >Building a RESTful API with Koa and Postgres - Michael Herman
The API itself should follow RESTful design principles, using the basic HTTP verbs: GET, POST, PUT, and DELETE.
Read more >Timers | Node.js v19.3.0 Documentation
Because the timer functions are globals, there is no need to call ... When called, the active Timeout object will not require the...
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 >
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
@briandamaged It makes sense now!
This modification would solve my problem. But what if timeout rejects first? In my code the query handler would be cleaned up by db.destory(), but in general case?
@elhigu : Makes sense. In that case, we might just need to cancel the
setTimeout(..)
call like @prk3 suggested.