You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "chenBright (via GitHub)" <gi...@apache.org> on 2026/10/07 13:17:02 UTC
[PR] Fix stack argument race in priority bthread scheduling (brpc)
chenBright opened a new pull request, #3587:
URL: https://github.com/apache/brpc/pull/3587
### What problem does this PR solve?
Issue Number: resolve
Problem Summary:
Priority queue tests can intermittently crash under load. After
`priority_to_run()` enqueues a preempted parent bthread, another worker can
resume it and reuse its stack. Reading `args->tag` afterward can pass a
corrupted tag to `signal_task()`, causing an invalid ParkingLot access.
### What is changed and the side effects?
Changed:
Copy `ReadyToRunArgs` before publishing the parent to the priority queue.
Side effects:
- Performance effects:
- Breaking backward compatibility:
---
### Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow [Contributor Covenant Code of Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Fix stack argument race in priority bthread scheduling (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on PR #3587:
URL: https://github.com/apache/brpc/pull/3587#issuecomment-6076465076
@wwbmmm PTAL.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Fix stack argument race in priority bthread scheduling (brpc)
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3587:
URL: https://github.com/apache/brpc/pull/3587#discussion_r4208091697
##########
test/bthread_priority_queue_unittest.cpp:
##########
@@ -246,4 +247,75 @@ TEST_F(PriorityQueueTest, multiple_eds_concurrent_preempt) {
ASSERT_EQ((size_t)TOTAL, g_executed_ids.size());
}
+// Reuse the frames left by bthread_start_urgent instead of leaving the
+// scheduler's on-stack ReadyToRunArgs intact after the parent resumes.
+NOINLINE void reuse_stack_after_start_urgent() {
+ bthread_tag_t tags[256];
+ for (int& tag : tags) {
+ tag = BTHREAD_TAG_INVALID;
+ }
+}
Review Comment:
This helper's only effect is writing a non-volatile local array that is never observed, so an optimizing compiler may reduce it to a no-op even though it is marked `NOINLINE`. In that build the test does not actually overwrite the parent's `ReadyToRunArgs` stack frame and can pass without exercising the reported race; make the writes volatile or otherwise expose an observable result.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Fix stack argument race in priority bthread scheduling (brpc)
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm merged PR #3587:
URL: https://github.com/apache/brpc/pull/3587
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org