Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with auto failover with CONNECT_TIMEOUT host #988

Open
n3xt-kyle opened this issue Nov 26, 2024 · 1 comment
Open

Issue with auto failover with CONNECT_TIMEOUT host #988

n3xt-kyle opened this issue Nov 26, 2024 · 1 comment

Comments

@n3xt-kyle
Copy link

Related to but different than #815

const pgsql = postgres({
  host: "host1,host2,host3",
  port: 5432,
  user: "username",
  password: "password",
  database: "app",
  target_session_attrs: primary,
  max: 20,
  connect_timeout: 3
});

when host1 is offline, resulting in a CONNECT_TIMEOUT on the socket then the postgres client errors with the following and does not attempt to connect to host2 or host3:

Error: write CONNECT_TIMEOUT host1:5432
Stack: Error: write CONNECT_TIMEOUT host1:5432
    at connectTimedOut (node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:257:20)
    at Timeout.done [as _onTimeout] (node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:1033:8)
    at listOnTimeout (node:internal/timers:596:11)
    at process.processTimers (node:internal/timers:529:7)

when host1 is online, but not listening on port then the postgres library connects to host2 or host3, as appropriate based on primary session attrs.

when we change our config to only connect to host1 when it is not listening on port:

const pgsql = postgres({
 host: "host1",
 port: 5432,
 user: "username",
 password: "password",
 database: "app",
 max: 20,
});

we get the following error when trying to connect to the db via this postgres client library

Error:
Stack: AggregateError [ECONNREFUSED]:
    at internalConnectMultiple (node:net:1121:18)
    at internalConnectMultiple (node:net:1189:5)
    at afterConnectMultiple (node:net:1688:7)

It's as if ECONNREFUSED is handled in the desired way but CONNECT_TIMEOUT is not.

@porsager
Copy link
Owner

Do you think you can set up a failing test case ? (there's a limited amount of multi-host tests in the repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants