Add ability to set connect timeout
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:3
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Add Timeout Capability to Express Apps with connect-timeout
We can do this by making requests that take too long to time out. The connect-timeout middleware can help us do this.
Read more >What is "Connect Timeout" in sql server connection string?
It specifies how long you will allow your program to be held up while it establishes a database connection.
Read more >Connect Timeout - Akamai TechDocs
Timeout, Sets the connection timeout value in seconds, minutes, hours, or days. The default is 5 seconds.
Read more >Configuring connection timeout on Message Processors
Add the property connect.timeout.millis with an appropriate value under the <HTTPTargetConnection> element in the TargetEndpoint configuration. For example, to ...
Read more >Timeouts • Akka HTTP - Documentation
The idle-timeout is a setting which sets the maximum inactivity time of a given connection. If no data is sent or received on...
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
hi @nfitch,
I was looking for the same thing. I am not using the pool feature, but pg.Client directly. I was playing with a couple of ideas.
Example 1:
In Example 1, if a query takes longer than 2 seconds to return results I think it will also trigger that timeout. So here was another idea I had if you just wanted to have a connection timeout.
These are just some ideas. Let me know your thoughts.
@charmander thanks a lot for taking a look at that.
The context I am actually using that function is during a connection test. So, after the promise is resolved I do
client.end()
in the caller.Thanks for showing me how to force kill: I will use it.
Gonna edit my previous comment to add a note to not confuse anybody 😃