Skip to content

Call OpenSSL cleanup before safeExit to fix LeakSanitizer false positives - #98296

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-openssl-lsan-false-positive
Feb 28, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-openssl-lsan-false-positive

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Call OpenSSLInitializer::cleanup before safeExit in the forced server shutdown path
  • When the server force-exits via safeExit → _exit, static destructors are bypassed, so OPENSSL_cleanup never runs
  • ASan intercepts _exit and runs LSan, which reports OpenSSL global cached state as leaked memory
  • This fixes false-positive "Sanitizer" failures in AST fuzzer CI jobs

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97652&sha=c9d73d1a85abfa220c6ddad38d81e7acb72be2e9&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan%29
#97652

Changelog category (leave one):

  • CI Fix or improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix LeakSanitizer false positives for OpenSSL on forced server shutdown.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.156

…izer false positives

When the server takes the forced shutdown path via `safeExit` → `_exit`,
static destructors and atexit handlers are bypassed, so
`OpenSSLInitializer::cleanup` / `OPENSSL_cleanup` never runs.
ASan intercepts `_exit` and runs LSan, which reports OpenSSL's global
cached state (EVP method cache, legacy provider context) as leaked memory.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97652&sha=c9d73d1a85abfa220c6ddad38d81e7acb72be2e9&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4cfb8644]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_debug) failure
Logical error: Function writeSlice expects same column types for GenericArraySlice and GenericArraySink. (STID: 2549-45e3) FAIL cidb

@thevar1able

Copy link
Copy Markdown
Member

Sanitizer report mentions KeeperServer, does it make sense to add the same to programs/keeper/Keeper.cpp?

@alexey-milovidov alexey-milovidov self-assigned this Feb 28, 2026
The same `safeExit` pattern exists in `programs/keeper/Keeper.cpp`.
Apply the same `OpenSSLInitializer::cleanup` call to avoid
LeakSanitizer false positives in Keeper as well.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Done.

@alexey-milovidov
alexey-milovidov merged commit bf8d8ab into master Feb 28, 2026
143 of 144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-openssl-lsan-false-positive branch February 28, 2026 20:14
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 28, 2026
alexey-milovidov added a commit that referenced this pull request Feb 28, 2026
…anitizer false positives

`safeExit` calls `_exit`, which bypasses static destructors and atexit
handlers. ASan intercepts `_exit` and runs LSan, which then reports
memory from libraries (e.g., OpenSSL global state) as leaked because
their cleanup routines never ran.

By calling `__lsan_do_leak_check` before `_exit`, the leak check runs
while all memory is still reachable through global pointers, and the
subsequent at-exit check is disabled. This prevents false positives
without requiring per-library cleanup calls.

Supersedes #98296 (reverted in #98354).
#98354

Co-Authored-By: Claude Opus 4.6 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Mar 1, 2026
…tive

Call OpenSSL cleanup before safeExit to fix LeakSanitizer false positives
@CheSema CheSema added the post-rejected Should've been rejected, but got merged. label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

post-rejected Should've been rejected, but got merged. pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants