You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix inconsistent ownership handling in SelectiveChannel::AddChannel on failure (#1408) - #3595
This failure contract is not honored when AddChannel is called before SelectiveChannel::Init: SelectiveChannel::AddChannel returns at selective_channel.cpp:582-584 without deleting an OWNS_CHANNEL argument. That externally reachable failure still leaves ownership with the caller, contrary to the new API guarantee and PR's “OWNS always takes over” rule. Handle ownership on this path (and cover it in the test), or explicitly narrow the contract.
Attach user before returning on IOEvent initialization failure to ensure proper cleanup.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
[replied by brpc-oncall robot] Both of chenBright's findings are valid, and there is a deeper reason they cannot be fixed only in the callers: this path now invokes BeforeRecycle on a Socket that is still half-constructed, so Socket::BeforeRecycled() itself will dereference the not-yet-created _transport (and destroy the not-yet-initialized _id_wait_list) after running the callback — the _user attachment should be dropped and the PR kept scoped to schan (or BeforeRecycledmade safe for a partially constructed Socket first). Also note that Socket::Create can fail before OnCreated runs, in which case no callback runs, so "delete sub_chan or not" cannot be decided at the AddChannel call site with a single unconditional choice; the failure handling needs a mechanism that covers both.
The reason will be displayed to describe this comment to others. Learn more.
[replied by brpc-oncall robot] The set_user handoff resolves the previous issues cleanly: creation failures never run a recycle callback so AddChannel disposes the wrapper itself, while post-creation failures rely on SubChannel::BeforeRecycle, and the dead re-address block is gone. One inconsistency remains between the newly documented failure contract and the not-initialized path.
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
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.
What problem does this PR solve?
Issue Number: resolve #1408
Problem Summary:
SelectiveChannel::AddChannel各失败路径对用户 sub channel 的所有权处理不一致:有的泄漏(OWNS 时未删用户 channel / 已创建的 fake Socket 未回收),有的行为不统一,调用方无法预判,容易泄漏或 double free。What is changed and the side effects?
Changed:
Socket::Create失败时按 ownership 手动回收;其余失败路径对 fake Socket 调SetFailed()+ReleaseHCRelatedReference(),由SubChannel::BeforeRecycle按 ownership 清理;重复 channel 返回 -1 且不改变任何东西。补充注释并新增单测。Side effects:
Check List: