Skip to content

Don't recycle connections on RELOAD if TLS config is unchanged#1157

Merged
JelteF merged 24 commits into
pgbouncer:masterfrom
cosgroveb:skip_disconnect_if_tls_config_unchanged
Sep 14, 2024
Merged

Don't recycle connections on RELOAD if TLS config is unchanged#1157
JelteF merged 24 commits into
pgbouncer:masterfrom
cosgroveb:skip_disconnect_if_tls_config_unchanged

Conversation

@cosgroveb

@cosgroveb cosgroveb commented Sep 3, 2024

Copy link
Copy Markdown
Contributor

This addresses #1145.

We run pgbouncers client-side that connect to 80+ databases. Separately we are addressing this bottleneck by running more pgbouncers client-side and striping them but in order to eliminate the unnecessary queuing that this kind of aggressive connection recycling can cause I propose taking a more judicious approach.

Essentially, I propose:

  1. If going from TLS disabled => enabled, recycle.
  2. If changing sslmode, recycle.
  3. If changing TLS config, recycle.
  4. Otherwise do nothing.

It's kind of gross that I have to inspect each member of the lengthy TLS config struct. Comments in-line.

Comment thread src/sbuf.c Outdated
Comment thread src/sbuf.c Outdated
@cosgroveb

Copy link
Copy Markdown
Contributor Author

3 out of 4 of my new tests fail in CI under a --without-opensslbuild :|

FAILED test/test_operations.py::test_servers_disconnect_when_changing_tls_config - AssertionError
FAILED test/test_operations.py::test_servers_disconnect_when_enabling_ssl - AssertionError
======= 3 failed, 144 passed, 9 skipped, 9 warnings in 96.52s (0:01:36) ========

Maybe I'm missing a marker/annotation. 👀

@cosgroveb

Copy link
Copy Markdown
Contributor Author

Okay, moved my tests into test_ssl so they only run in the right builds and addressed the uncrustify build.

@cosgroveb cosgroveb force-pushed the skip_disconnect_if_tls_config_unchanged branch from 2d10623 to 73adecd Compare September 3, 2024 11:05
Comment thread test/test_ssl.py
Comment thread src/sbuf.c Outdated
Comment thread src/sbuf.c Outdated
Comment thread test/test_ssl.py Outdated

@JelteF JelteF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks like a good improvement. Currently we indeed recycle connections way too aggressively when TLS is enabled.

Comment thread src/sbuf.c Outdated
Comment thread src/sbuf.c Outdated
Comment thread src/sbuf.c Outdated
Comment thread src/sbuf.c Outdated
Comment thread src/sbuf.c Outdated
Comment thread test/test_ssl.py Outdated
Comment thread test/test_ssl.py
@cosgroveb cosgroveb force-pushed the skip_disconnect_if_tls_config_unchanged branch 2 times, most recently from 9e5aa5a to 129a01b Compare September 4, 2024 14:28
cosgroveb added a commit to cosgroveb/libusual that referenced this pull request Sep 4, 2024
In pgbouncer, we'd like to be able to compare TLS configs for equality
to avoid over-aggressive connection recycling. Since knowledge about
the structure for these configs live here it seems best to implement
that here.

Original PR: pgbouncer/pgbouncer#1157
…-> test_ssl so they are only run with SSL tests in CI
… is checking out a connection and also at the full_maint_period
@cosgroveb cosgroveb force-pushed the skip_disconnect_if_tls_config_unchanged branch from 1c373c5 to a9d1859 Compare September 4, 2024 22:37
cosgroveb added a commit to cosgroveb/libusual that referenced this pull request Sep 4, 2024
In pgbouncer, we'd like to be able to compare TLS configs for equality
to avoid over-aggressive connection recycling. Since knowledge about
the structure for these configs live here it seems best to implement
that here.

Original PR: pgbouncer/pgbouncer#1157
@cosgroveb cosgroveb force-pushed the skip_disconnect_if_tls_config_unchanged branch 2 times, most recently from dabc457 to 60e8d71 Compare September 4, 2024 23:56
@cosgroveb cosgroveb force-pushed the skip_disconnect_if_tls_config_unchanged branch from 60e8d71 to 58b77a5 Compare September 5, 2024 20:31
@cosgroveb

Copy link
Copy Markdown
Contributor Author

Hey @JelteF I think I've addressed any outstanding feedback. I did force push the branch on Wednesday to rewrite my git ùser.email`. Sorry if that was bad form or made reviewing the final state of this harder.

I presume we need to wait for my outstanding libusual PR to be reviewed/merged to get this pull merged? Any tips on getting the libusual PR reviewed?

Thanks for being so responsive and helpful in getting this operational bottleneck in pgbouncer solved.

cosgroveb added a commit to cosgroveb/libusual that referenced this pull request Sep 7, 2024
In pgbouncer, we'd like to be able to compare TLS configs for equality
to avoid over-aggressive connection recycling. Since knowledge about
the structure for these configs live here it seems best to implement
that here.

Original PR: pgbouncer/pgbouncer#1157
@JelteF

JelteF commented Sep 7, 2024

Copy link
Copy Markdown
Member

I presume we need to wait for my outstanding libusual/libusual#57 to be reviewed/merged to get this pull merged? Any tips on getting the libusual PR reviewed?

All PgBouncer committers also have commit access on libusual (including me). So this should be fine. But yeah we should merge that one first.

Comment thread doc/config.md Outdated
cosgroveb added a commit to cosgroveb/libusual that referenced this pull request Sep 8, 2024
In pgbouncer, we'd like to be able to compare TLS configs for equality
to avoid over-aggressive connection recycling. Since knowledge about
the structure for these configs live here it seems best to implement
that here.

Original PR: pgbouncer/pgbouncer#1157
@cosgroveb

Copy link
Copy Markdown
Contributor Author

@JelteF I've branched a cleanup from this to remove strings_equal() and use the libusual library function as discussed there and will PR that as soon as the libusual PR and this one are merged.

@JelteF

JelteF commented Sep 8, 2024

Copy link
Copy Markdown
Member

CI is reporting a failure on one of the newly added tests, looks like it's flaky since only one of the linux builds is hitting the issue.

JelteF pushed a commit to libusual/libusual that referenced this pull request Sep 8, 2024
In pgbouncer, we'd like to be able to compare TLS configs for equality
to avoid over-aggressive connection recycling. Since knowledge about the
structure for these configs live here it seems best to implement that
here.

Original PR: pgbouncer/pgbouncer#1157
@cosgroveb

Copy link
Copy Markdown
Contributor Author

I haven't had success with any specs at all with valgrind enabled locally today to repro but will give it another try tonight

@cosgroveb

cosgroveb commented Sep 9, 2024

Copy link
Copy Markdown
Contributor Author

Okay @JelteF these specs were genuinely flaky due to timing issues between full_maint_period refreshes and clients checking out a connection. This spec was one that didn't sleep for full_maint_period and didn't expect that style of refresh from the logs but got one:

2024-09-08 18:04:35.379 UTC [12865] LOG S-0x53ccd50: pTxnPool/bouncer@127.0.0.1:10201 closing because: database configuration changed (age=0s)

This isn't incorrect behavior. Updating the expectation to avoid this: e27c774

`full_maint_period` refreshes clients checking out a connection. This
spec was one that didn't sleep for `full_maint_period` and didn't expect
that style of refresh from the logs but got one:

```2024-09-08 18:04:35.379 UTC [12865] LOG S-0x53ccd50:
pTxnPool/bouncer@127.0.0.1:10201 closing because: database configuration
changed (age=0s)
```

This isn't incorrect behavior. This commit updates the expectation to
avoid this issue.
@cosgroveb cosgroveb force-pushed the skip_disconnect_if_tls_config_unchanged branch from dfd74cb to 3b76c63 Compare September 9, 2024 23:13
@cosgroveb

Copy link
Copy Markdown
Contributor Author

Any further changes needed @JelteF ?

@JelteF JelteF left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM now

@JelteF JelteF enabled auto-merge (squash) September 14, 2024 11:06
@JelteF JelteF merged commit b0c5d98 into pgbouncer:master Sep 14, 2024
@cosgroveb cosgroveb deleted the skip_disconnect_if_tls_config_unchanged branch October 19, 2024 14:11
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.

3 participants