Repository navigation
Fix UDF registry loss during Keeper session expiry - #101891
Conversation
When refreshObjects() loads UDFs from ZooKeeper and the session expires mid-loop, tryLoadObject() was catching the exception and returning nullptr. The partially-loaded set was then passed to setAllObjects(), which replaced the entire in-memory registry — causing all UDFs that failed to load to become UNKNOWN_FUNCTION until the next successful refresh cycle. The fix has two parts: 1. tryLoadObject() now re-throws Keeper hardware errors (session expired, connection loss) instead of silently returning nullptr. Non-hardware errors and parse failures still return nullptr as before. 2. refreshObjects() now uses ZooKeeperRetriesControl to retry the entire load loop on Keeper hardware errors with exponential backoff (200ms initial, 5s max, 10 retries). setAllObjects() is only called after a fully successful load. If all retries are exhausted, the exception propagates to the caller and the existing registry is preserved intact.
|
Workflow [PR], commit [59cc611] Summary: ❌
AI ReviewSummaryThis PR fixes a real correctness issue in ClickHouse Rules
Final Verdict
|
| @@ -0,0 +1,116 @@ | |||
| """ | |||
There was a problem hiding this comment.
This looks like an accidental duplicate of tests/integration/test_replicated_user_defined_functions_keeper_fault/test.py committed under the repository tmp/ tree.
Please remove this file from the PR. Keeping test sources under tmp/ is fragile (it is typically used for transient/local artifacts) and can cause confusion about which test is authoritative.
| "destination_port": 2181, | ||
| "protocol": "tcp", | ||
| "action": "DROP", | ||
| "probability": 0.9, |
There was a problem hiding this comment.
This test uses probabilistic packet loss (probability: 0.9) plus fixed time.sleep(10) windows, so it is inherently nondeterministic and can be flaky in both directions: it may fail even when code is correct (no matching log within the time window), or pass without reliably reproducing the target race.
Please make the failure injection deterministic (for example: force a full disconnect long enough to guarantee session expiration, then restore connectivity and trigger refresh explicitly) and gate assertions with retry/polling on an observable state transition rather than fixed sleeps.
…, use SYSTEM RELOAD FUNCTIONS
… retry loop, remove test ClickHouse/clickhouse-private#54946
LLVM Coverage Report
Changed lines: 72.97% (27/37) | lost baseline coverage: 4 line(s) · Uncovered code |
Backport #101891 to 26.2: Fix UDF registry loss during Keeper session expiry
Backport #101891 to 26.3: Fix UDF registry loss during Keeper session expiry
The `ZooKeeperRetriesControl` retry loop introduced in #101891 reused the same expired ZooKeeper session on every retry iteration, without calling `renewZooKeeper` as every other retry loop in the codebase does. This caused repeated requests on a finalized session, leading to crashes (clickhouse-core-incidents #1644, #1645). Remove the broken retry loop. The `tryLoadObject` split-catch that re-throws Keeper hardware errors is sufficient: the exception propagates to `processWatchQueue`'s catch-all, which resets the session and retries from scratch with a fresh connection. This preserves the original fix's goal — `setAllObjects` is never called with a partial set — without the stale-session misuse.
Backport #101891 to 26.1: Fix UDF registry loss during Keeper session expiry
Fix
UserDefinedSQLObjectsZooKeeperStorage::refreshObjectsreplacing the in-memory UDF registry with a partial set when Keeper session expires mid-refresh.tryLoadObjectcaught all exceptions including Keeper hardware errors, so remaining UDFs silently becamenullptrandsetAllObjectsoverwrote the registry.Split the catch block in
tryLoadObjectto re-throw Keeper hardware errors (session expired, connection loss). Wrap the load loop inZooKeeperRetriesControl::retryLoopwith exponential backoff.setAllObjectsonly executes after a fully successful load — if retries are exhausted, the existing registry is preserved.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix UDF registry loss when ZooKeeper session expires during periodic refresh — all user-defined functions could become unavailable until a full refresh succeeds.
Documentation entry for user-facing changes
Version info
26.4.1.63526.3.5.6,26.2.8.16,26.1.8.23