fix(base): avoid self-deadlock during runtime drop#20103
Open
dqhl76 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
Fix a runtime self-deadlock that can happen when the last
Arc<Runtime>is dropped from one of that runtime's own worker tasks.Root Cause
The existing runtime design moves the real Tokio runtime into a
wait-to-drop-*OS thread. Dropping Databend's outerRuntimesends a stop signal and then joins that thread.That is safe when the drop happens from outside the runtime. It deadlocks when the last reference is dropped by one of the runtime's own worker tasks:
The worker waits for wait-to-drop, while wait-to-drop waits for the worker.
In the observed query case, failed SQL can abort the outer pipeline early. That changes ownership order so a pruning task may hold the last
Arc<PruningContext>. Dropping that context drops itspruning_runtimefrom inside apruning-workertask, triggering the self-deadlock.Tests
Type of change
This change is