Repository navigation
Let replication handle_disconnect/1 update connection options - #810
palermo-git wants to merge 1 commit into
Conversation
|
Can you please provide more context here? Which status reports are including the process dictionary? What is logging the output of The reason I ask is because, even if you put it in the configure callback, then if someone can execute code in the system, they will still be able to access the credentials somehow. Also we recently introduced opaque structs to hide credentials and we could use that instead of introducing new callbacks. |
|
Thanks, you're right, and I overstated it in the description. I went back and measured (PG 16, OTP 28, Elixir 1.19.7; run and script below):
So that alone isn't worth new API. The reason I'd still like Run: https://github.com/palermo-git/postgrex/actions/runs/45023077058 · Script: https://github.com/palermo-git/postgrex/blob/postgrex-810-repro/repro.exs |
|
A concrete consumer, for context: replicant is a change-data-capture library built on |
|
I am thinking I'd rather figure out a way to change the connection within the running process, since we control the process in this case, than setting it up via configure? |
|
That works for us: replicant's connection module is the callback module, so it can resolve credentials itself. One gap to cover: a reconnect after a live disconnect runs Two shapes I can see:
Which would you prefer? I'll rework #810 to match. |
|
Let's try 2. |
|
Reworked as option 2:
Tests in CI on my fork (this branch plus a trigger commit for push builds): https://github.com/palermo-git/postgrex/actions/runs/45190844985 (PG 9.4–18 and lint, all green). I also merged master to pick up v0.23.0. |
handle_disconnect/1 may return {:noreply, connect_options, state}. The options are merged into those used for every later connection attempt, with the same normalization as start_link/3, so a callback module can refresh a rotated password. With auto_reconnect: true, handle_disconnect/1 also runs after each failed connection attempt, before the backoff.
1cfda73 to
f443f78
Compare
|
Squashed onto current master (daf1530) as one commit. No code change from the previous head: the diff against master is identical to the earlier net diff. CI on my fork (this commit plus a trigger line for push builds) is green on PG 9.4–18: https://github.com/palermo-git/postgrex/actions/runs/46692375858 |
Postgrex.ReplicationConnectionreconnects with the options captured at start, so a long-lived replication connection keeps retrying a stale password after a credential rotation. This lets the callback module refresh them:handle_disconnect/1may return{:noreply, connect_options, state}. The keyword list is merged into the options used for all later connection attempts, so[password: refreshed]is enough. Merged options get the same normalization asstart_link/3(string ports become integers,nilfalls back to the default, endpoint keys are replaced as a group).:parameterskeepsreplication: "database".:auto_reconnect,:reconnect_backoffand:sync_connectare startup-only and ignored. Withauto_reconnect: falsethe process stops after the callback, so returned options are checked but not merged.auto_reconnect: true,handle_disconnect/1also runs after each failed connection attempt, before the backoff, including the initial attempt. The state may never have been connected. This is listed under backwards incompatible changes in the CHANGELOG.Tests (
test/replication_reconnect_test.exs, real PostgreSQL, PG 10+): rotation after a live disconnect, recovery after failed attempts (sync and async initial connect, consecutive backoffs), option normalization and endpoint replacement, ignored startup options, invalid returns, and theauto_reconnect: falsestop paths.CI on my fork (this branch plus a trigger commit for push builds): https://github.com/palermo-git/postgrex/actions/runs/45190844985, PG 9.4–18 and lint all green.