Skip to content

branch-4.1: [fix](brpc) Make secondary package aliases non-owning #65777#65819

Open
gavinchou wants to merge 1 commit into
apache:branch-4.1from
gavinchou:gavin-pick-65777-branch-4.1
Open

branch-4.1: [fix](brpc) Make secondary package aliases non-owning #65777#65819
gavinchou wants to merge 1 commit into
apache:branch-4.1from
gavinchou:gavin-pick-65777-branch-4.1

Conversation

@gavinchou

Copy link
Copy Markdown
Contributor

Pick brpc thirdparty patch from #65777 for branch-4.1.\n\nThis PR only changes thirdparty/patches/brpc-1.4.0-secondary-package-name.patch. It intentionally does not include the master-only thirdparty/build-thirdparty.sh change from #65777.\n\nThe fix makes secondary brpc package aliases non-owning to avoid double delete during brpc::Server shutdown.\n\nValidation:\n- git diff --check\n- bash thirdparty/download-thirdparty.sh brpc\n\nIssue: DORIS-27128

@gavinchou
gavinchou requested a review from yiguolei as a code owner July 20, 2026 09:22
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@gavinchou

Copy link
Copy Markdown
Contributor Author

run buildall

@gavinchou

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review result: request changes

The collision-free direct brpc::Server destruction path is improved: when primary and secondary names are distinct, the patch leaves one service/status owner and avoids the reported duplicate deletes. Three issues still need resolution:

  • Explicit RemoveService and registration rollback leave the secondary aliases in BRPC maps after their shared targets are deleted, enabling stale lookup and restart-time use-after-free.
  • If secondary_package_name equals the primary package, the non-owning assignments overwrite the only owning entries and leak the service/status objects.
  • The Cloud lifecycle test still disables the exact non-empty alias branch, so lookup and owned teardown remain untested.

Critical checkpoint conclusions:

  • Goal and correctness: the normal distinct-key ClearServices double-free is addressed, but removal/rollback and equal-key behavior keep the lifecycle fix incomplete.
  • Lifecycle and error handling: M-001 is blocking because public removal and post-insertion failure paths leave dangling map entries.
  • Configuration and compatibility: the setting is an unrestricted string and doris.cloud exactly reaches M-002. No wire, protocol, or storage-format compatibility change applies.
  • Concurrency: no new race or locking defect was found; BRPC service mutation is READY-state only and direct destruction stops/joins first.
  • Scope, performance, and observability: the ownership delta is focused. No new material hot-path or observability regression was substantiated; duplicate alias map walks predate this ownership-only change.
  • Persistence, transactions, and data writes: not applicable to this third-party in-memory registration patch.
  • Testing and validation: static review only under the runner contract. git diff --check is clean, but local third-party sources/install/protoc are absent. Cloud UT is skipped, and the failed macOS-arm64 third-party job stops on an unrelated libunwind patch before reaching BRPC, so there is no runtime proof of the changed branch.
  • User focus: no additional focus was provided; the complete PR was reviewed.

Review completion: complete. The sole changed file and its BRPC/Doris upstream and downstream paths were reviewed through two rounds; both Round 2 reviewers returned NO_NEW_VALUABLE_FINDINGS, and every candidate was accepted, deduplicated, or dismissed with evidence. The three accepted points are attached inline.

+ _fullname_service_map[secondary_full_name] = ss;
+ ServiceProperty secondary_ss = ss;
+ secondary_ss.ownership = SERVER_DOESNT_OWN_SERVICE;
+ _fullname_service_map[secondary_full_name] = secondary_ss;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Erase these aliases when removing the service

Making the alias non-owning avoids the destructor double free, but BRPC 1.4.0 RemoveMethodsOf erases only md->full_name() (plus the IDL no-namespace alias), and RemoveService erases only sd->full_name()/sd->name(). Therefore AddService with a secondary package followed by RemoveService—or an AddServiceInternal rollback—deletes the primary MethodStatus and, on owning paths, the service while these secondary entries remain. A later Find* returns dangling state, and Start() dereferences the freed status/service. Please erase the secondary method and service keys on every removal/rollback before deleting the shared objects.

+ secondary_method_name.append(md->name());
+ _method_map[secondary_method_name] = mp;
+ MethodProperty secondary_mp = mp;
+ secondary_mp.own_method_status = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve ownership when the alias equals the primary package

secondary_package_name is unrestricted; for MetaService, setting it to its current package doris.cloud makes secondary_full_name equal sd->full_name() and the derived method keys equal md->full_name(). FlatMap::operator[] then overwrites the just-inserted owning entries with these non-owning copies, so ClearServices/RemoveService no longer deletes the MethodStatus or the SERVER_OWNS_SERVICE allocation. Reject or skip an alias equal to the primary name before assigning it, and preflight any other occupied alias key.

+ secondary_method_name.push_back('.');
+ secondary_method_name.append(md->name());
+ _method_map[secondary_method_name] = mp;
+ MethodProperty secondary_mp = mp;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Add a runtime regression for this ownership branch

The Cloud lifecycle test currently forces config::secondary_package_name = "" specifically to avoid brpc::Server::~Server() crashing, so no test executes this changed non-owning branch. The patch/download checks prove only that the third-party patch applies. Please enable a distinct non-empty alias in a test, assert both service/method names resolve, and destroy or ClearServices() an owning server; the removal and equal-package cases above should also be covered.

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 72.95% (28598/39204)
Line Coverage 56.36% (309245/548711)
Region Coverage 53.63% (258559/482144)
Branch Coverage 54.57% (113495/207979)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants