Skip to content

Improve connection fail fast logic #998

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

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

JelteF
Copy link
Member

@JelteF JelteF commented Dec 22, 2023

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
Copy link
Contributor

khanova commented Dec 22, 2023

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
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
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
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
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 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
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