Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disagg: Fix a potential crash when shutting down #8848

Merged
merged 4 commits into from
Mar 15, 2024

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Mar 15, 2024

What problem does this PR solve?

Issue Number: close #8837

Problem Summary:

There is a logging about "std::exception. Code: 1001, type: std::__1::system_error, e.what() = thread::join failed: Resource deadlock avoided". Usually it is caused by a thread is trying to call join for the thread itself.

There is a chance that the task handle (shared_ptr) is being held by the background pool thread

TaskHandle task = tryPopTask(rng);
if (shutdown)
break;

And the task handle could hold a shared_ptr to UniversalPageStorageService. So there could be a chance that:

  1. The main thread receive kill signal, UniversalPageStorageService::shutdown is called
  2. But there is a background pool thread holding a shared_ptr of remote_checkpoint_handle, which contains a shared_ptr of UniversalPageStorageService
  3. The shared_ptr of UniversalPageStorageService in the ContextShared is released
  4. The background pool thread try to release to shared_ptr of remote_checkpoint_handle, which cause the shared_ptr of UniversalPageStorageService being released. But the thread is created by UniversalPageStorageService::checkpoint_pool. So the thread run into calling join on itself and causing the system_error

What is changed and how it works?

Use a weak_ptr of UniversalPageStorageService instead of shared_ptr. So that even when the remote_checkpoint_handle is still holding by the background pool thread, it won't cause the background pool thread calling join on itself. Because the share counter of UniversalPageStorageService must go down to 0 outside of the background pool thread.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix a potential crash when shutting down under disagg arch

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed do-not-merge/needs-triage-completed labels Mar 15, 2024
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Mar 15, 2024
@JaySon-Huang JaySon-Huang self-assigned this Mar 15, 2024
Copy link
Member

@CalvinNeo CalvinNeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

ti-chi-bot bot commented Mar 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CalvinNeo, JinheLin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 15, 2024
Copy link
Contributor

ti-chi-bot bot commented Mar 15, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-03-15 10:34:34.520597427 +0000 UTC m=+1027301.542843815: ☑️ agreed by JinheLin.
  • 2024-03-15 14:41:23.482701727 +0000 UTC m=+1042110.504948112: ☑️ agreed by CalvinNeo.

@ti-chi-bot ti-chi-bot bot merged commit bffeab1 into pingcap:master Mar 15, 2024
6 checks passed
@CalvinNeo
Copy link
Member

Meanwhile, I don't think it's a good idea to make a ThreadPool lives actually shorter than its tasks.
The holder should release the ThreadPool only after all its workers are idle.

@JaySon-Huang JaySon-Huang deleted the fix_uni_ps_shutdown branch March 15, 2024 14:48
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Apr 9, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #8914.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disaggregated TiFlash crash when the process is shutting down
4 participants