pg.end() doesn't always end the connections
See original GitHub issueSimple testcase:
var opts = {
"driver": "postgres",
"host": "localhost",
"user": "nodetest",
"password": "password",
"database": "nodetest"
}
var pg = require('pg');
pg.connect(opts, function(err, client) {
pg.end();
});
Then executing it:
% time node test_pg.js
^Cnode test_pg.js 2.49s user 0.66s system 0% cpu 14:10.42 total
I halted the program after 14 minutes. If I modify it like this:
var opts = {
"driver": "postgres",
"host": "localhost",
"user": "nodetest",
"password": "password",
"database": "nodetest"
}
var pg = require('pg');
pg.connect(opts, function(err, client) {
client.query('select * from person', function(){
pg.end();
});
});
Then it works:
% time node test_pg.js
node test_pg.js 0.12s user 0.02s system 11% cpu 1.142 total
Issue Analytics
- State:
- Created 11 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
node module pg client.end() doesn't close connections
If you are using a connection pool, you cannot end connections. You will have to release the connections back to the pool to...
Read more >Websites don't load - troubleshoot and fix error messages
Close the Connection Settings dialog. Close the about:preferences page. Any changes you've made will automatically be saved. The problem happens in all web ......
Read more >iCloud data security overview - Apple Support
The keys are always stored and secured in Apple data centers. Apple doesn't access or store keys for any end-to-end encrypted data. Information ......
Read more >RFC 7230: Hypertext Transfer Protocol (HTTP/1.1)
A tunnel ceases to exist when both ends of the relayed connection are closed. ... where the Location header field doesn't parse according...
Read more >What is HTTP Keep Alive | Benefits of Connection ... - Imperva
By default, HTTP connections close after each request. ... Enabling the keep-alive header allows you to serve all web page resources over a...
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 FreeTop 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
Top GitHub Comments
Ehm… According to the docs, calling pg.end will kill any connection (not cleanly). It specifically says it is intended for unit tests. I came across this bug because my unit tests were not ending even when I called pg.end().
pg.end should work correctly now
I’ve changed the pool substantially to no longer rely on the
drain
event at all. NopauseDrain
noresumeDrain
. Documentation is a work in progress.https://github.com/brianc/node-postgres/wiki/pg https://github.com/brianc/node-postgres/pull/274