Skip to content

Fix SIGSEGV due to CPU/Real profiler#63865

Merged
nikitamikhaylov merged 1 commit intoClickHouse:masterfrom
azat:fix-query-profiler-SIGSEGV
May 16, 2024
Merged

Fix SIGSEGV due to CPU/Real profiler#63865
nikitamikhaylov merged 1 commit intoClickHouse:masterfrom
azat:fix-query-profiler-SIGSEGV

Conversation

@azat
Copy link
Copy Markdown
Member

@azat azat commented May 15, 2024

The problem was due to incorrect unwinding due from signal handlers, which leads to incorrect DWARF (FDE/CIE) interpretation.

After this patch I was not able to reproduce the crash for couple of hours, while before it was very stable (I've reduced the minimal threshold for query_profiler_real_time_period_ns), using simply:

$ clickhouse-benchmark --port 19000 -q "SELECT * FROM remote('127.{1..10}', system, one)" --query_profiler_real_time_period_ns=1

Note, I'm using here remote() for fibers, that has stack with guard pages that helps with reproducing the crash more faster.

P.S. I also have another implementation of this fix, without patching unwind and using info from signal context directly, and even though it is better, because you don't need to trip extra frames and you can use all the 45 frames for something useful, it is too complex, so let's go with a simpler patch first, and I think it could be even backported.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix SIGSEGV due to CPU/Real (query_profiler_real_time_period_ns/query_profiler_cpu_time_period_ns) profiler (has been an issue since 2022, that leads to periodic server crashes, especially if you were using distributed engine)

Fixes: #60460
Fixes: #33531
Fixes: #60219
Refs: ClickHouse/libunwind#25
Refs: llvm/llvm-project#92291

The problem was due to incorrect unwinding due from signal handlers,
which leads to incorrect DWARF (FDE/CIE) interpretation.

After this patch I was not able to reproduce the crash for couple of
hours, while before it was very stable (I've reduced the minimal
threshold for query_profiler_real_time_period_ns), using simply:

    $ clickhouse-benchmark --port 19000 -q "SELECT * FROM remote('127.{1..10}', system, one)" --query_profiler_real_time_period_ns=1

Note, I'm using here remote() for fibers, that has stack with guard
pages that helps with reproducing the crash more faster.

P.S. I also have another implementation of this fix, without patching
unwind and using info from signal context directly, and even though it
is better, because you don't need to trip extra frames and you can use
all the 45 frames for something useful, it is too complex, so let's go
with a simpler patch first, and I think it could be even backported.

Signed-off-by: Azat Khuzhin <[email protected]>
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-bugfix Pull request with bugfix, not backported by default submodule changed At least one submodule changed in this PR. labels May 15, 2024
@robot-clickhouse-ci-2
Copy link
Copy Markdown
Contributor

robot-clickhouse-ci-2 commented May 15, 2024

This is an automated comment for commit 94041d1 with description of existing statuses. It's updated for the latest CI running

❌ Click here to open a full report in a separate page

Check nameDescriptionStatus
CI runningA meta-check that indicates the running CI. Normally, it's in success or pending state. The failed status indicates some problems with the PR⏳ pending
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests❌ failure
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests❌ failure
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc❌ failure
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors❌ failure
Successful checks
Check nameDescriptionStatus
A SyncThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
ClickHouse build checkBuilds ClickHouse in various configurations for use in further steps. You have to fix the builds that fail. Build logs often has enough information to fix the error, but you might have to reproduce the failure locally. The cmake options can be found in the build log, grepping for cmake. Use these options and follow the general build process✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integrational tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Mergeable CheckChecks if all other necessary checks are successful✅ success
PR CheckThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@alexey-milovidov
Copy link
Copy Markdown
Member

@azat Let's fix all CI failures.

@azat
Copy link
Copy Markdown
Member Author

azat commented May 16, 2024

Failures does not looks related, most of them are flaky

Integration tests (tsan) [1/6] — fail: 1, passed: 439

  • test_broken_projections/test.py::test_mutation_with_broken_projection - unrelated and flaky

Integration tests (tsan) [5/6] — fail: 1, passed: 574

  • test_storage_s3/test.py::test_seekable_formats_url - flaky

Stateful tests (release, ParallelReplicas) — fail: 1, passed: 131, skipped: 5

  • 00088_global_in_one_shard_and_rows_before_limit - flaky

Stress test (debug) — Hung check failed, possible deadlock found (see hung_check.log)

Looks like some hang in - will take a look later

/build/src/IO/ParallelReadBuffer.cpp:290::DB::ParallelReadBuffer::finishAndWait()
/build/src/IO/ParallelReadBuffer.h:33::DB::ParallelReadBuffer::~ParallelReadBuffer()
/build/src/IO/ParallelReadBuffer.h:33::DB::ParallelReadBuffer::~ParallelReadBuffer()

Performance Comparison [2/4] — 2 errors, 2 too long, 1 faster, 1 unstable

The error for the query is

clickhouse_driver.errors.ServerException: Code: 159.
select_format.query4.run0: DB::Exception: Timeout exceeded: elapsed 19.931821772 seconds, maximum: 15. Stack trace:

But it fails on the left server anyway (i.e. upstream/master), and sometimes it's execution took ~15 seconds, will take a look later.

The query is INSERT INTO table_PrettySpace SELECT * FROM test.hits LIMIT 10000, the problem is likely due to:

@nikitamikhaylov nikitamikhaylov self-assigned this May 16, 2024
@nikitamikhaylov nikitamikhaylov added this pull request to the merge queue May 16, 2024
@filimonov
Copy link
Copy Markdown
Contributor

Backports?

@azat
Copy link
Copy Markdown
Member Author

azat commented May 28, 2024

Agree, make sense (it should not make anything worse)

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created-cloud deprecated label, NOOP label May 29, 2024
robot-ch-test-poll2 added a commit that referenced this pull request May 29, 2024
Backport #63865 to 24.3: Fix SIGSEGV due to CPU/Real profiler
nikitamikhaylov added a commit that referenced this pull request May 29, 2024
Backport #63865 to 24.4: Fix SIGSEGV due to CPU/Real profiler
nikitamikhaylov added a commit that referenced this pull request May 29, 2024
Backport #63865 to 24.2: Fix SIGSEGV due to CPU/Real profiler
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 29, 2024
shiyer7474 added a commit to Altinity/ClickHouse that referenced this pull request Sep 2, 2024
yokofly added a commit to timeplus-io/proton that referenced this pull request Jan 22, 2026
…d update)

* ClickHouse/ClickHouse#63865 from azat/fix-query-profiler-SIGSEGV

Fix SIGSEGV due to CPU/Real profiler

* ClickHouse/ClickHouse#60468 from ClickHouse/libunwind-fix-crash

Fix crash in libunwind while interpreting debug info

* ClickHouse/ClickHouse#65509 Update libunwind to 18.1.7

* ClickHouse/ClickHouse#66850 from ClickHouse/revert-libunwind-patch

Revert libunwind patch

* ClickHouse/ClickHouse#66977 from ClickHouse/uwo

Apply libunwind fix

* ClickHouse/ClickHouse#68312 from ClickHouse/muslwind

Apply libunwind changes needed for musl

* ClickHouse/ClickHouse#76107 from ClickHouse/owo

Apply libunwind fix for DwarfFDECache

* ClickHouse/ClickHouse#76136 from ClickHouse/revert-76107-owo

Revert "Apply libunwind fix for DwarfFDECache"

* ClickHouse/ClickHouse#76178 from ClickHouse/unw

Apply libunwind fix for DwarfFDECache, attempt 2

* Update libunwind to aec8e58

* ClickHouse/ClickHouse#67152 from ClickHouse/ohno

Uncomment accidentally commented out code in QueryProfiler

* ClickHouse/ClickHouse#64058  aarch64 sigaltstack size fix

* ClickHouse/ClickHouse#58607 Added null guards to avoid potential demangle crashes

---------

Co-authored-by: Nikita Mikhaylov <[email protected]>
Co-authored-by: Alexey Milovidov <[email protected]>
Co-authored-by: Michael Kolupaev <[email protected]>
Co-authored-by: Antonio Andelic <[email protected]>
Co-authored-by: Max Kainov <[email protected]>
yokofly added a commit to timeplus-io/proton that referenced this pull request Jan 23, 2026
…d update) (#11324)

* ClickHouse/ClickHouse#63865 from azat/fix-query-profiler-SIGSEGV

Fix SIGSEGV due to CPU/Real profiler

* ClickHouse/ClickHouse#60468 from ClickHouse/libunwind-fix-crash

Fix crash in libunwind while interpreting debug info

* ClickHouse/ClickHouse#65509 Update libunwind to 18.1.7

* ClickHouse/ClickHouse#66850 from ClickHouse/revert-libunwind-patch

Revert libunwind patch

* ClickHouse/ClickHouse#66977 from ClickHouse/uwo

Apply libunwind fix

* ClickHouse/ClickHouse#68312 from ClickHouse/muslwind

Apply libunwind changes needed for musl

* ClickHouse/ClickHouse#76107 from ClickHouse/owo

Apply libunwind fix for DwarfFDECache

* ClickHouse/ClickHouse#76136 from ClickHouse/revert-76107-owo

Revert "Apply libunwind fix for DwarfFDECache"

* ClickHouse/ClickHouse#76178 from ClickHouse/unw

Apply libunwind fix for DwarfFDECache, attempt 2

* Update libunwind to aec8e58

* ClickHouse/ClickHouse#67152 from ClickHouse/ohno

Uncomment accidentally commented out code in QueryProfiler

* ClickHouse/ClickHouse#64058  aarch64 sigaltstack size fix

* ClickHouse/ClickHouse#58607 Added null guards to avoid potential demangle crashes

---------

Co-authored-by: Nikita Mikhaylov <[email protected]>
Co-authored-by: Alexey Milovidov <[email protected]>
Co-authored-by: Michael Kolupaev <[email protected]>
Co-authored-by: Antonio Andelic <[email protected]>
Co-authored-by: Max Kainov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backports-created-cloud deprecated label, NOOP pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libunwind: getSavedRegister: invalid read from memory Frequent segfaults in large processing job Segfault in libunwind

8 participants