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.

Feature: query timeout

See original GitHub issue

I want to start a discussion about built in query timeout.

In our production environment, we encountered a problem with TCP connections getting stuck. Knex pool would fill up with connections that are not responsive. Note that this would be different from statement timeout, where DB decides to terminate query. Instead pg client would decide that connection is unresponsive and emit an error.

This situation can be simulated with firewall rule:

sudo iptables -A INPUT -j DROP -p tcp --destination-port 5432

Or just use this code snippet:

const { Client } = require('pg')
const client = new Client({user: "user", password: "pass", database: "db"})
const util = require('util');
const exec = util.promisify(require('child_process').exec);

async function main() {
   await exec("sudo iptables -D INPUT -j DROP -p tcp --destination-port 5432");
   await client.connect()

   console.log("Client connected");
   await exec("sudo iptables -A INPUT -j DROP -p tcp --destination-port 5432");

   console.log("Now waiting for DB to respond... forever")
   const res = await client.query('SELECT $1::text as message', ['Hello world!'])
   console.log(res.rows[0].message) // Hello world!
   await client.end()
   process.exit(0)
}

main()

A possible implementation can be found here: https://github.com/brianc/node-postgres/compare/master...juliusza:query_timeout I know I need to add tests and also edit the native driver code for a proper PR. But first I’m looking for feedback from the community to assert if such a thing would be useful.

Also perhaps

socket.setTimeout(3000);

could be a viable solution. I need to look into that.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brianccommented, Nov 30, 2018

yay!

0reactions
vitaly-tcommented, Nov 30, 2018

Can this be closed now or there is still a problem with the sockets?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot query time-out errors - SQL Server
This article describes how to troubleshoot the time-out errors when you run slow-running queries.
Read more >
How to Define the Timeout of a Query - OpenbravoWiki
Query timeouts are defined using timeout profiles. A timeout profile represents a server-side activity. For instance, the GRID timeout profile, defined in core, ......
Read more >
The queryTimeout SPARQL query hint - Amazon Neptune
The queryTimeout query hint specifies a timeout that is shorter than the neptune_query_timeout value set in the DB parameters group. If the query...
Read more >
Server-side SELECT statement timeouts - MySQL
After the specified number of milliseconds has passed, the server aborts the individual query without affecting the larger transaction or ...
Read more >
Query Timeout - Informatica Documentation
Set the. SSADB_QUERY_TIMEOUT. environment variable. · Specify the. --query_timeout. parameter when you run the Relate client. · Use the. ids_set_timeout. function ...
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