Skip to content

Add ability to set connect timeout #397

Closed
@nfitch

Description

@nfitch

I read the docs on client options:
https://github.com/brianc/node-postgres/wiki/Client#constructor

And didn't see a way to set the connection timeout. A simple example of what I'd like to tune:

var pg = require('pg');

//Assuming no machine with ip 192.168.255.255 exists
var client = new pg.Client('tcp://root:root@192.168.255.255');
var start = (new Date()).getTime();
client.connect(function (err) {
        var end = (new Date()).getTime();
        console.log({
                err: err,
                elapsedTime: end - start
        });
});

Results in:

[nate@dev madtom]$ node ./test/postgres_timeout.js
{ err:
   { [Error: connect ECONNREFUSED]
     code: 'ECONNREFUSED',
     errno: 'ECONNREFUSED',
     syscall: 'connect' },
  elapsedTime: 75818 }

Notice that the elapsed time is 75 seconds.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions