Skip to content

Improve connection fail fast logic - #998

Merged
JelteF merged 1 commit into
pgbouncer:masterfrom
JelteF:improve-connection-fail-fast
Jan 16, 2024
Merged

JelteF merged 1 commit into
pgbouncer:masterfrom
JelteF:improve-connection-fail-fast

Conversation

@JelteF

@JelteF JelteF commented Dec 22, 2023 •

Copy link
Copy Markdown
Member

For a very long time, we've had logic to quickly close all clients when
the a server could not be connected to.

This wasn't working correctly in all cases, one of those was when an
auth_user was set (and no auth_db). This was reported in #989.

While looking closer into that issue I realized it also wouldn't handle
cases where first connecting worked but then after a while it doesn't
anymore, because it relied only on wait_for_welcome. It's not strictly
necessary to kill all waiting connections when creating new server
connections is not possible anymore, as long as there are still working
server connections. But if those don't exist either, then we're
effectively in the same state as complete refresh (except that we have
cached the welcome message).

Fixes #989
Fixes #985

@khanova

khanova commented Dec 22, 2023

Copy link
Copy Markdown
Contributor

Thanks a lot for looking into it!
This PR fixes our issue with pgbouncer.

@JelteF
JelteF force-pushed the improve-connection-fail-fast branch from 052e7a6 to e366f63 Compare January 2, 2024 15:00
For a very long time, we've had logic to quickly close all clients when
the a server could not be connected to.

This wasn't working correctly in all cases, one of those was when an
auth_user was set (and no auth_db). This was reported in pgbouncer#989.

While looking closer into that issue I realized it also wouldn't handle
cases where first connecting worked but then after a while it doesn't
anymore, because it relied only on `wait_for_welcome`. It's not strictly
necessary to kill all waiting connections when creating new server
connections is not possible anymore, as long as there are still working
server connections. But if those don't exist either, then we're
effectively in the same state as complete refresh (except that we have
cached the welcome message).

Fixes pgbouncer#989
Fixes pgbouncer#985

Co-Authored-By: Anna Khanova <annakhanova@neon.tech>
@JelteF
JelteF force-pushed the improve-connection-fail-fast branch from e366f63 to 171ec14 Compare January 15, 2024 10:56
Comment thread src/server.c
kill_pool_logins_server_error(server->pool, pkt);
else
log_server_error("S: login failed", pkt);
kill_pool_logins_server_error(server->pool, pkt);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to remove the below log?
log_server_error("S: login failed", pkt);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now always call kill_pool_logins_server_error and that already logs the error using:

log_warning("server login failed: %s %s", level, msg);

(it's a warning not an error this time, but that seems like a not very important change)

@emelsimsek

Copy link
Copy Markdown
Contributor

Changes look fine to me.

@JelteF
JelteF merged commit 163a748 into pgbouncer:master Jan 16, 2024
@JelteF
JelteF deleted the improve-connection-fail-fast branch January 16, 2024 09:09
@bayandin bayandin mentioned this pull request Feb 2, 2024
1 of 5 tasks
bayandin added a commit to neondatabase/neon that referenced this pull request Feb 2, 2024
## Problem
Update pgbouncer from 1.21 (and patches[0][1]) to 1.22 (which includes
these patches)
- [0] pgbouncer/pgbouncer#972
- [1] pgbouncer/pgbouncer#998

## Summary of changes
- Build pgbouncer 1.22.0 for neonVMs from upstream
zeekay pushed a commit to hanzosql/neon that referenced this pull request Sep 10, 2026
## Problem
Update pgbouncer from 1.21 (and patches[0][1]) to 1.22 (which includes
these patches)
- [0] pgbouncer/pgbouncer#972
- [1] pgbouncer/pgbouncer#998

## Summary of changes
- Build pgbouncer 1.22.0 for neonVMs from upstream
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

Successfully merging this pull request may close these issues.

When connecting to a new non-existing database pgbouncer doesn't report it

3 participants