Repository navigation
Fix socket reference leak during removal and revival - #3691
Merged
Merged
Conversation
chenBright
force-pushed
the
fix-socket-ref-and-options
branch
from
October 30, 2026 15:27
b3ed979 to
477124a
Compare
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
What changed in this PR
Fixes a socket reference leak when socket removal races with health-check revival by distinguishing “additional ref released due to failure” vs “additional ref permanently released,” and ensures SelectiveChannel cleanup prevents revival after removal.
Changes:
- Introduce new additional-ref states to prevent Revive() from restoring the additional ref after permanent removal.
- Update SelectiveChannel cleanup/removal paths to always mark permanent removal before releasing the HC-related reference.
- Add unit tests covering removal↔revival race orderings, invalid SelectiveChannel LB initialization, and removal preventing revival.
| File | Description |
|---|---|
| test/brpc_socket_unittest.cpp | Adds tests for removal/revival ordering and concurrent racing. |
| test/brpc_channel_unittest.cpp | Adds tests for invalid SelectiveChannel LB init and removal preventing revival. |
| src/brpc/versioned_ref_with_id.h | Adds permanent vs failure-only additional-ref states and ref-release coordination with Revive(). |
| src/brpc/selective_channel.cpp | Ensures permanent removal is recorded before releasing HC-related refs; adds unified cleanup guard. |
| src/brpc/load_balancer.cpp | Changes invalid LB protocol handling from LOG(FATAL) to LOG(ERROR) + return error. |
Review effort: Lite
Copilot stopped reviewing on behalf of
chenBright due to an error
October 30, 2026 16:41
Contributor
Author
Contributor
|
please resolve merge conflict |
chenBright
force-pushed
the
fix-socket-ref-and-options
branch
from
October 31, 2026 09:26
477124a to
dee691a
Compare
Contributor
Author
@wwbmmm done. |
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.


What problem does this PR solve?
Issue Number: resolve
Problem Summary:
Removing a failed socket can race with health-check revival and leak an additional reference.
The leak occurs because removal assumes the additional reference is already gone, but health
checking restores it afterward, leaving nobody responsible for releasing it.
What is changed and the side effects?
Changed:
Distinguish references released by
SetFailed()from permanent owner releases. Coordinateremoval with revival and update SelectiveChannel cleanup accordingly.
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: