Repository navigation
Fix a crash at shutdown when a static still owns an S3 client - #133151
alexey-milovidov merged 1 commit into
Conversation
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding, 0 on the re-run) plus my own cold review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261120-070505 |
|
cc @zvonand, could you review this? ClientCacheRegistry was a destructible function-local static, so an S3 client owned by a static built before it (the KeeperDispatcher cached in KeeperSpans.cpp, when keeper_server.s3_snapshot arrives by a config reload) unregistered from the destroyed registry at exit; the registry is now never destroyed, the UntrackedMemoryRegistry idiom. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261120-051205 |
|
Workflow [PR], commit [15e8723] Summary: ✅
AI ReviewSummaryThe change keeps Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 11 s compile time in total, 7 of them have a recent master baseline. |
`S3::Client::~Client` unregisters from `ClientCacheRegistry::instance()`, which was a destructible function-local static. Statics are destroyed in reverse order of construction completion, and the registry is built by the first S3 client of the process. A static that already owned an S3 client before that point is destroyed after the registry, and its `~Client` then calls `find` on a destroyed `unordered_map`: libc++ frees the nodes and nulls the bucket array but keeps `bucket_count`, so `find` loads from `nullptr + 8 * idx` (SIGSEGV; UBSan "applying non-zero offset 8 to null pointer" at unique_ptr.h:545). Such an owner exists: `ZooKeeperOpentelemetrySpans::maybeFinalizeImpl` caches `static const auto keeper_dispatcher = getKeeperDispatcher();`, a strong reference that keeps `KeeperDispatcher::snapshot_s3` and its `S3::Client` alive until static destruction. With Keeper tracing on, the static is built by the first traced Keeper request; adding `keeper_server.s3_snapshot` by a configuration reload then creates the first S3 client, and so the registry, after it. Measured: the official 26.3.63.123 and 26.8.37.168 images and master exit with SIGSEGV at shutdown; without the reload, or with Keeper tracing off, they exit 0. Allocate the registry once and never delete it, as `UntrackedMemoryRegistry::instance()` does for the same hazard. It stays reachable through the static pointer, so LSan does not report it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
49ddd02 to
15e8723
Compare
CI finish ledger - 15e8723Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261120-143035 |
4aa16c6
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a crash at server shutdown when
keeper_server.s3_snapshotis added by a configuration reload while Keeper OpenTelemetry tracing (opentelemetry_start_keeper_trace_probability) is enabled.Description
On 26.3.63.123 and 26.8.37.168 (official images) and on master, a server with embedded Keeper,
opentelemetry_span_logandopentelemetry_start_keeper_trace_probability = 1exits with SIGSEGV at shutdown afterkeeper_server.s3_snapshotis added bySYSTEM RELOAD CONFIG. An ASan+UBSan build reports:~S3::Clientunregisters fromClientCacheRegistry, a function-local static. Statics are destroyed in reverse order of construction, so a client owned by a static constructed before the registry is destroyed after it, andunregisterClientsearches a destroyedunordered_map. Here the owner is theKeeperDispatchercached in a static inKeeperSpans.cpp(built by the first traced Keeper request): it keepssnapshot_s3and its client alive until exit, while the reload creates the process's first S3 client, and so the registry, after it.The registry is now never destroyed, the idiom of
UntrackedMemoryRegistry(#120386). It stays reachable through the static pointer, so LSan does not report it. Fixing the registry rather than theKeeperSpanscache covers every static owner of a client, including transitive ones.Validation: the server scenario below exits 139 on master, 26.3 and 26.8 (an ASan+UBSan master build exits 134 with the report above) and 0 with the fix; without the reload, or with Keeper tracing off, 26.8 exits 0. No public issue or CI report exists.
Server reproduction
<zookeeper>pointing at it and<pass_opentelemetry_tracing_context>1</pass_opentelemetry_tracing_context>;opentelemetry_span_logconfigured; default profileopentelemetry_start_trace_probability = 1,opentelemetry_start_keeper_trace_probability = 1; no S3 disk, table or collection.SYSTEM RECONNECT ZOOKEEPER, then aReplicatedMergeTreeCREATE and INSERT (spans carryingraft.roleappear insystem.opentelemetry_span_log).<keeper_server><s3_snapshot><endpoint>http://127.0.0.1:1/snapshots/</endpoint><access_key_id>x</access_key_id><secret_access_key>y</secret_access_key></s3_snapshot></keeper_server>and runSYSTEM RELOAD CONFIG(KeeperSnapshotManagerS3: S3 client was updated; the endpoint is never contacted).Application: shutting down; with this PR it exits 0.Workflow [PR]
Sync PR [sync-upstream/pr/133151]
Version info
26.12.1.99-master(included in26.12and later)