Handle low queue TryRecvError and fix test message#252
Conversation
Reviewer's GuideThis PR enhances fairness drain logic by handling disconnected low-priority channels, streamlines callback and pattern matching, enforces consistent multi-line formatting for methods, replaces dead-code expect attributes with comments, and updates a test’s failure message. Sequence diagram for fairness drain handling of disconnected low-priority channelsequenceDiagram
participant Connection
participant FairnessConfig
participant LowPriorityQueue as mpsc::Receiver
participant ActorState
participant Hooks
participant OutVec as Vec<F>
Connection->>FairnessConfig: should_yield()
alt should_yield is true
Connection->>LowPriorityQueue: try_recv()
alt Ok(frame)
Connection->>Hooks: before_send(frame, ctx)
Connection->>OutVec: push(frame)
Connection->>FairnessConfig: after_low()
else TryRecvError::Empty
Note right of Connection: Do nothing
else TryRecvError::Disconnected
Connection->>Connection: handle_closed_receiver(&mut low_rx, state)
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/connection.rs:404` </location>
<code_context>
fn after_high(&mut self, out: &mut Vec<F>, state: &mut ActorState) {
self.fairness.after_high();
</code_context>
<issue_to_address>
Consider restructuring after_high to use early returns and an if-let for clarity instead of mapping over Option.
You can simplify after_high by reverting the `.as_mut().map(…)` into an `if let Some(…)` and pulling your `should_yield` check up front. That way the reader sees “we only try_recv if there’s a queue and we should yield,” and you don’t construct an intermediate `Option<Result<…>>`. For example:
```rust
fn after_high(&mut self, out: &mut Vec<F>, state: &mut ActorState) {
self.fairness.after_high();
// only drain when fairness wants us to yield, and only if we have a receiver
if !self.fairness.should_yield() {
return;
}
if let Some(rx) = &mut self.low_rx {
match rx.try_recv() {
Ok(mut frame) => {
self.hooks.before_send(&mut frame, &mut self.ctx);
out.push(frame);
self.after_low();
}
Err(TryRecvError::Disconnected) => {
// handle the closed queue
Self::handle_closed_receiver(&mut self.low_rx, state);
}
Err(TryRecvError::Empty) => {
// nothing to do
}
}
}
}
```
This preserves exactly the same behavior but removes the extra `map` + inner `if let`, so the control-flow reads straight down.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| @@ -393,21 +404,28 @@ where | |||
| fn after_high(&mut self, out: &mut Vec<F>, state: &mut ActorState) { | |||
There was a problem hiding this comment.
issue (complexity): Consider restructuring after_high to use early returns and an if-let for clarity instead of mapping over Option.
You can simplify after_high by reverting the .as_mut().map(…) into an if let Some(…) and pulling your should_yield check up front. That way the reader sees “we only try_recv if there’s a queue and we should yield,” and you don’t construct an intermediate Option<Result<…>>. For example:
fn after_high(&mut self, out: &mut Vec<F>, state: &mut ActorState) {
self.fairness.after_high();
// only drain when fairness wants us to yield, and only if we have a receiver
if !self.fairness.should_yield() {
return;
}
if let Some(rx) = &mut self.low_rx {
match rx.try_recv() {
Ok(mut frame) => {
self.hooks.before_send(&mut frame, &mut self.ctx);
out.push(frame);
self.after_low();
}
Err(TryRecvError::Disconnected) => {
// handle the closed queue
Self::handle_closed_receiver(&mut self.low_rx, state);
}
Err(TryRecvError::Empty) => {
// nothing to do
}
}
}
}This preserves exactly the same behavior but removes the extra map + inner if let, so the control-flow reads straight down.
* Replace unwraps with expect * Add expect macros and document infallible call * Use push_expect macros in connection actor tests Replace verbose await/expect pairs with the push_expect! helper to standardise low- and high-priority push failure messages. Rewriting let-chain expressions to nested conditionals keeps the build on stable Rust, and lint expectations were relaxed accordingly. * Apply formatting * Handle low queue TryRecvError and fix test message (#252) * Handle missing TryRecvError and fix test message * Apply formatting * Collapse nested conditionals (#253) * Remove unneedeed carriage returns * Remove unneedeed carriage returns * Remove unused struct * Remove unused struct
Summary
Testing
make lintmake testhttps://chatgpt.com/codex/tasks/task_e_688f6464f5108322871f4bdd33a91738
Summary by Sourcery
Handle low-priority channel disconnections during fairness draining, unify code formatting conventions, simplify conditional logic, and update test and example annotations and messages
Bug Fixes:
Enhancements:
Documentation:
Tests: