[p2p] stop background receiver when consumer channel closes#3308
[p2p] stop background receiver when consumer channel closes#3308sashass1315 wants to merge 1 commit intocommonwarexyz:mainfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| Self::handle_decode_result(&mut self.blocker, &mut self.sender, result).await; | ||
| if !Self::handle_decode_result(&mut self.blocker, &mut self.sender, result).await { | ||
| break; | ||
| } |
There was a problem hiding this comment.
While-loop break doesn't exit the run loop
Low Severity
When handle_decode_result returns false (consumer closed) inside the on_start while loop, the break only exits the while loop, not the outer loop generated by select_loop!. The post-while check on line 226 only tests saw_error and receiver_closed && decode_pool.is_empty() — it doesn't account for consumer closure. The consumer.closed() biased select branch catches this on the same iteration, so behavior is correct, but the gap is inconsistent with how saw_error propagates and could become a real bug if the select branches are reordered or the consumer.closed() fallback is removed.


WrappedBackgroundReceiverpreviously ignored downstream closure and continued decoding/spawning work even after the consumer channel was dropped. This change makes decode handling return a continuation signal, exits the run loop when send_lossy indicates closure, and adds explicit closed-channel checks before scheduling new decode tasks. Added a regression test to ensure the background task exits promptly when the consumer is dropped.