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.

pg.end() doesn't always end the connections

See original GitHub issue

Simple 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:closed
  • Created 11 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fsatelercommented, Mar 30, 2012

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().

0reactions
brianccommented, Feb 22, 2013

pg.end should work correctly now

I’ve changed the pool substantially to no longer rely on the drain event at all. No pauseDrain no resumeDrain. Documentation is a work in progress.

https://github.com/brianc/node-postgres/wiki/pg https://github.com/brianc/node-postgres/pull/274

Read more comments on GitHub >

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

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