Make batch create stream SendFeedback thread safe#3215
Make batch create stream SendFeedback thread safe#3215jenrryyou wants to merge 1 commit intoapache:masterfrom
Conversation
|
Can you add some unit test to verify this scenario? |
ok, I will try to add it. |
3ac4cfa to
d37798a
Compare
• 新增用例:test/brpc_streaming_rpc_unittest.cpp(StreamingRpcTest.batch_create_stream_feedback_race) • 核心思路:服务端max_buf_size设置为16B。客户端批量创建 2 条 stream,刻意阻塞 extra stream 的 SetConnected()(锁住其 _connect_mutex),让 extra stream 先 Consume() 到 64B 数据后再放开 SetConnected();修复后 SetConnected() 会基于 _atomic_local_consumed 立刻补发首个 FEEDBACK(consumed_size=64),从而使服务端 extra stream的第二次 StreamWrite(1B) 不再长期 EAGAIN,避免错误反压。如果没有这个修复,这个单测会直接因为错误反压而hang住。 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a race in the batch stream creation path where Stream::SetConnected() and the consumer queue (Consume()) can run concurrently, causing SendFeedback to report an incorrect consumed byte count and potentially triggering incorrect backpressure on the sender.
Changes:
- Make stream connection state and pre-connect consumed-byte accounting thread-safe using atomics.
- Update
SendFeedbackto accept an explicit consumed-byte value to avoid racing on shared state. - Add a unit test that reliably reproduces the batch-create
SetConnected()vsConsume()feedback race.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
test/brpc_streaming_rpc_unittest.cpp |
Adds a regression test that enlarges the race window and asserts FEEDBACK unblocks the sender correctly. |
src/brpc/stream_impl.h |
Updates internal stream state (_connected, consumed tracking) and changes SendFeedback signature. |
src/brpc/stream.cpp |
Implements atomic connection/consumed logic and sends an initial FEEDBACK after connect when needed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d37798a to
96fc748
Compare
96fc748 to
71b7595
Compare
What problem does this PR solve?
Issue Number: resolve
Fixes #2754
Problem Summary:
批量创建stream场景下,解决 Stream SetConnected() 与 Consume() 并发导致的 SendFeedback
发送与已消费字节统计的竞态问题,使得反馈的已消费字节数准确,避免发送端错误反压。
What is changed and the side effects?
Changed:
Side effects:
兼容
Check List: