Skip to content

native connect failures seem to leak resources #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jlfaber opened this issue Aug 15, 2013 · 2 comments
Closed

native connect failures seem to leak resources #417

jlfaber opened this issue Aug 15, 2013 · 2 comments

Comments

@jlfaber
Copy link

jlfaber commented Aug 15, 2013

node-pg: 2.3.1
macos: 10.8.4
node: 0.8.22

Repeated calls to pg.connect when the pg server is not running will eventually start to return a different error suggesting that there's a resource leak. The following snippet reproduces the issue:

var pg = require('pg').native;

var nAttempts = 250;

var handleConnectResponse = function (error, client, done) {
    if (error.code !== 'ECONNREFUSED' && error.message.slice(0, 17) !== 'could not connect') {
        console.log('UNEXPECTED ERROR:', error);
    }
    //if (--nAttempts) { setTimeout(attemptToConnect, 10); }
    if (--nAttempts) { attemptToConnect(); }
};

var attemptToConnect = function () {
    return pg.connect('postgres://localhost/postgres', handleConnectResponse);
};

attemptToConnect();

In this configuration, the last several calls produce either "[Error: could not create socket: Too many open files" or "{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }". Changing the comment to call attemptToConnect after a short delay seems to avoid the "Too many open files" error, but still shows the other one for the last several calls. Obviously, you might need to modify nAttempts to repro this.

Note that the non-native version does not seem to have this problem. It does produce a different error, but it seems to do so consistently regardless of how many times pg.connect is called.

@brianc
Copy link
Owner

brianc commented Aug 17, 2013

That's troubling. I'll look into this one.

On Wed, Aug 14, 2013 at 9:03 PM, Joe Faber [email protected] wrote:

node-pg: 2.3.1
macos: 10.8.4
node: 0.8.22

Repeated calls to pg.connect when the pg server is not running will
eventually start to return a different error suggesting that there's a
resource leak. The following snippet reproduces the issue:

var pg = require('pg').native;
var nAttempts = 250;
var handleConnectResponse = function (error, client, done) {
if (error.code !== 'ECONNREFUSED' && error.message.slice(0, 17) !== 'could not connect') {
console.log('UNEXPECTED ERROR:', error);
}
//if (--nAttempts) { setTimeout(attemptToConnect, 10); }
if (--nAttempts) { attemptToConnect(); }};
var attemptToConnect = function () {
return pg.connect('postgres://localhost/postgres', handleConnectResponse);};
attemptToConnect();

In this configuration, the last several calls produce either "[Error:
could not create socket: Too many open files" or "{ [Error: getaddrinfo
ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo'
}". Changing the comment to call attemptToConnect after a short delay seems
to avoid the "Too many open files" error, but still shows the other one for
the last several calls. Obviously, you might need to modify nAttempts to
repro this.


Reply to this email directly or view it on GitHubhttps://github.com//issues/417
.

@davetapley davetapley mentioned this issue May 21, 2014
@brianc
Copy link
Owner

brianc commented Oct 20, 2014

Native bindings have been completely rewritten from scratch! Can you try now with

npm install [email protected]

Pretty sure this problem has gone away. :)

@brianc brianc closed this as completed Oct 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants