[BugFix] Fix transaction stream load lock leak (backport #53564) #53608
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.
Why I'm doing:
In transaction stream load, a normal load request needs to go through the
on_header
,on_chunk_data
, andhandle
processes of theTransactionStreamLoadAction
. To prevent concurrent load requests, a lock will be acquired inon_header
, and released inhandle
. But for an abnormal load request,handle
may be not called, and the lock will not be released. For example, the client crashes after transmitting a part of data, onlyon_header
andon_chunk_data
are called, andhandle
will not be called. This can lead to resources not being cleaned up after the load timeout because the cleanup needs acquire the lock (see TransactionMgr::_clean_stream_context).What I'm doing:
Move the lock release to
TransactionStreamLoadAction::free_handler_ctx
which will be always called regardless of whether an exception occurs or not.Fixes #53155
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request [BugFix] Fix transaction stream load lock leak #53564 done by Mergify.
Why I'm doing:
In transaction stream load, a normal load request needs to go through the
on_header
,on_chunk_data
, andhandle
processes of theTransactionStreamLoadAction
. To prevent concurrent load requests, a lock will be acquired inon_header
, and released inhandle
. But for an abnormal load request,handle
may be not called, and the lock will not be released. For example, the client crashes after transmitting a part of data, onlyon_header
andon_chunk_data
are called, andhandle
will not be called. This can lead to resources not being cleaned up after the load timeout because the cleanup needs acquire the lock (see TransactionMgr::_clean_stream_context).What I'm doing:
Move the lock release to
TransactionStreamLoadAction::free_handler_ctx
which will be always called regardless of whether an exception occurs or not.Fixes #53155
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist: