5

Over the last few days I've started to see read ETIMEDOUT errors in production, coming from Postgres (with node-postgres) and I'm having a tough time getting to the source of the problem.

I'm not sure whether the problem is that the database is unable to handle the connection, or whether it's something to do with being unable to acquire a connection from the pool, let alone write to the socket.

I can't recreate the error in development at all (and I can't recreate reliably in production either). Nothing is showing up in the Postgres error logs though.

Here's the pool configuration:

pool: { 
  max: 50, 
  min: 0, 
  idle: 20000, 
  acquire: 20000 
}

As far as I can see, the maximum number of connections we've had concurrently over the last month is 8, so the pool should never have been depleted.

Does Postgres have any kind of configurable query timeout that could be adjusted to make sure that long running queries aren't causing these? Although just for reference, sometimes these are happening for tiny inserts or single row reads.

I'm fairly sure that ETIMEDOUT is a system error, not something thrown by the high level JavaScript drivers. Where is the timeout for the underlying socket defined?

3
  • Probably a network problem like a firewall. Are there corresponding entries in the PostgreSQL log? Commented Mar 2, 2018 at 20:46
  • @LaurenzAlbe I think it's unlikely to be a firewall problem as 99.9% of queries don't fail. We don't currently have Postgres set up to log individual queries either, so unfortunately, I can't match them up. Commented Mar 2, 2018 at 20:49
  • Any further findings? I have same issue but I do not have much ideas about this. Commented Jun 28, 2024 at 0:25

1 Answer 1

1

Does Postgres have any kind of configurable idle timeout that could be adjusted to make sure that long running queries aren't causing these?

The idle timeout and the query timeout are two separate things.

The idle timeout is about how long a connection will hang in the connection pool before being closed due to non-use, and is configured via property idleTimeoutMillis of the connection object.

The query timeout defines how long the query can run before it times out, which is what you need. And it is configured via property statement_timeout of the connection object.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the heads up. I've updated the question. It looks like the default statement_timeout is set to be unlimited, so I'm not sure that's the problem.
@DanPrince Then maybe you need this: stackoverflow.com/questions/31904365/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.