Advice for debugging timeout/connection issues with Kysely
Hi everyone,
We've been using Kysely with pg in prod in our startup for over a year now and everything has been mostly stable, however, we started encountering these random errors with no seemingly obvious reason.
I am 99.9% sure that this is not a Kysely specific issue, but I'd be grateful if someone could advice us on how to debug these issues, as we don't have much experience in this. Googling revealed some stack overflow threads were timeout configs were discussed, but that didn't help us too much.
The error is:
connect ETIMEDOUT 20.208.39.81:5432
connect ETIMEDOUT 20.208.39.81:5432
.
The weird thing is that all the DB metrics are stable - memory, cpu, connections, etc.
Raising timeout values, or even making them indefinite does not seem to help.
We don't have too much data (2gb) and we rarely have queries that take more than a second to complete.
We set up our client like this:
const pool = new pg.Pool({ application_name: "Octocom Backend", connectionString: env.DB_URL, max: env.DB_POOL_SIZE, statement_timeout: 30_000, idle_in_transaction_session_timeout: 60_000,});pool.on("connect", (client) => { void client.query("SET lock_timeout = 30000");});const db = new Kysely<DB>({ log: env.DB_DEBUG ? console.log : undefined, dialect: new PostgresDialect({ pool, }), plugins: [new CamelCasePlugin()],});
const pool = new pg.Pool({ application_name: "Octocom Backend", connectionString: env.DB_URL, max: env.DB_POOL_SIZE, statement_timeout: 30_000, idle_in_transaction_session_timeout: 60_000,});pool.on("connect", (client) => { void client.query("SET lock_timeout = 30000");});const db = new Kysely<DB>({ log: env.DB_DEBUG ? console.log : undefined, dialect: new PostgresDialect({ pool, }), plugins: [new CamelCasePlugin()],});
First came Kysely, the type-safe query builder for TypeScript, then came people asking questions, then came the Discord server.Join if you like Kysely or have questions, or both.