Repository navigation
Conversation
Signed-off-by: Morchid Chellali <[email protected]>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (gateway); effort from diff stats (151+3 LOC, 1 files); LLM: Fixes a gateway bug where a bad GUC read fabricates a wrong If a label is wrong, remove it manually and ping |
AndrewKhoma
left a comment
There was a problem hiding this comment.
thanks for opening this PR, but I need a better explanation on how you've been able to reproduce and execute this state with the running postgresql
| }), | ||
| Err(e) => { | ||
| tracing::warn!("Failed to get connection for pg_file_settings: {e}"); | ||
| Vec::new() |
There was a problem hiding this comment.
this line and the line 102 (Vec::new() in unwrap_or_else) can be a potential bug you've faced, since we will drop all of the settings, not just the max_connections one in case of any failure instead of returning error
seems wrong to me, since in case of the error it's better to have stale GUCs then none
|
Thanks @AndrewKhoma — your inline comment is actually the repro. How the state is reached: it's exactly the On the fix: agreed — dropping every setting on a load error is probably a bug; stale GUCs beat none. I can rework this to keep the previous config on a failed refresh load and drop the now-unnecessary per-getter last-known-good. So — what to do then: A/ the load returns an error so the refresh skips the swap and keeps the last-good full config (my lean), or B/ merge onto the current map, upserting only successfully-read rows? Separately filed #724: the ~300s cadence is itself unexpected — we set |
Description
Fixes #720. Supersedes #721 (see "Why this instead of #721").
max_connectionsis a startup GUC — it cannot change without a Postgres restart — yetPgConfiguration::max_connections()(configuration/pg_configuration.rs) re-reads it on every dynamic-config refresh and silently substitutes25on a bad/missing read. Becausemax_connectionsis part of thePgPoolSettingspool-cache key, that fabricated25flips the key mid-run with no real change behind it;get_data_poolthen permanently hard-fails every request for that user ("Connection pool missing for user.") — the pool is healthy but orphaned. Full root cause and log evidence: #720.This fixes the root cause: on a bad read,
max_connections()returns the last successfully-read value instead of fabricating a divergent one, so the pool key stays stable and the spurious miss never happens.Why this instead of #721
#721 made
get_data_poolfall back to reusing the user's existing pool on a settings-key miss. As @AndrewKhoma noted in review, that is unsafe: ifmax_connectionshad genuinely dropped to 25, the reused (100-sized) pool would let requests use connections Postgres no longer has (over-subscription); and the user-pool hard-fail is intentional precisely becausemax_connectionsis a startup GUC. This PR takes that feedback directly — it does not reuse pools and leaves the intentional hard-fail guard inget_data_pooluntouched. It only removes the spurious key flip at its source (the bad read). A genuinemax_connectionschange (via restart → fresh read) still updates the value and flips the key as designed, so the intended rebuild path is preserved.What changed
max_connections()caches the last valid read in anAtomicUsize(stored on every valid read); on a bad read it returns that last-known-good value, falling back to25only on the first-read edge case. Scope: one field onPgConfiguration+ the getter.Testing
cargo test -p documentdb_gateway_core→ 434 passed, 0 failed, including two new tests (last-known-good on bad read; falls back to 25 with no prior good value) and the existingvalidate_max_conn_change(a real change still flips the key → pool rebuild preserved).rustfmtandclippy --workspace --all-targets --all-features -- -D warningsclean on the repo's pinned toolchain (Rust 1.95).Type of Change
AI Disclosure
Checklist
cargo test— 434 passed)Signed-off-by: Morchid Chellali [email protected]