Fix URMA polling shutdown lifetime by BGQ99 · Pull Request #3634 · apache/brpc · GitHub
Skip to content

Fix URMA polling shutdown lifetime - #3634

Open
BGQ99 wants to merge 2 commits into
apache:masterfrom
LinQuickDev:fix/urma-polling-shutdown
Open

BGQ99 wants to merge 2 commits into
apache:masterfrom
LinQuickDev:fix/urma-polling-shutdown

Conversation

@BGQ99

@BGQ99 BGQ99 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: Related to #3428

Problem Summary:

The normal process-exit path lacks a dedicated stop-and-join handler for URMA
polling workers, while poller groups are stored in an ordinary static vector.
Late Socket/UrmaEndpoint cleanup may enqueue CQ removal operations after the
poller queues have been destroyed.

What is changed and the side effects?

Changed:

  • Keep the poller-group vector alive for the process lifetime using a leaky singleton.
  • Register a polling-only atexit handler to stop and join polling workers, preserving the existing IOBuf pool lifetime because thread-local blocks may outlive atexit handlers.
  • Skip CQ add/remove operations when the group is no longer running.
  • Add regression tests for polling shutdown and process exit.

Validation (URMA mock):

  • CMake build passed with WITH_URMA=ON and URMA_USE_MOCK=ON.
  • All 20 tests passed.
  • An exit probe confirmed that polling workers completed their release callbacks before normal process exit.
  • git diff --check passed.

Side effects:

  • Performance effects: adds a running-state check to CQ registration/removal; the CQ polling loop is unchanged.

  • Breaking backward compatibility: no wire protocol or existing function signature changes. The poller-group container is intentionally retained until process termination.


Check List:

@wwbmmm
wwbmmm requested a balanced review from Copilot October 21, 2026 03:47

Copilot AI 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.

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

4 open issues
What changed in this PR

Fixes URMA polling worker shutdown ordering at process exit to prevent late endpoint/CQ cleanup from enqueueing operations into already-destroyed poller queues.

Changes:

  • Keep poller-group storage alive for process lifetime via a leaky singleton accessor.
  • Add an atexit handler that stops/joins URMA pollers without releasing the URMA IOBuf pool.
  • Add unit/death tests covering repeated release, late CQ ops after stop, and exit ordering.
File Description
test/​brpc_urma_unittest.cpp Adds regression and death tests for polling shutdown/release and exit ordering.
src/​brpc/​urma/​urma_helper.cpp Registers polling-only atexit shutdown handler when polling is enabled.
src/​brpc/​urma/​urma_endpoint.h Adds GlobalPollingModeRelease() API and switches poller-group storage to accessor.
src/​brpc/​urma/​urma_endpoint.cpp Implements leaky-singleton poller groups, global polling release, and running-state checks for CQ ops.

Review effort: Lite

Comment on lines +191 to +193
g_exit_endpoint = new urma::UrmaEndpoint(nullptr);
g_exit_endpoint->_resource = new urma::UrmaResource;
g_exit_endpoint->_cq_sid = 7;
Comment on lines +630 to +632
if (FLAGS_urma_use_polling) {
atexit(ReleasePollingModeAtExit);
}
Comment on lines +78 to +82
auto& group = urma::UrmaEndpoint::PollerGroups()[0];
EXPECT_FALSE(group.running.load());
for (const auto& poller : group.pollers) {
EXPECT_EQ(INVALID_BTHREAD, poller.tid);
}
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