Commit b4f985d
authored
fix(actor): drain Actor::tasks JoinSet in run_async (#96)
## Description
`Actor::tasks` is a `JoinSet<()>` that the three streaming-reply actions
(`Action::ListAuthors`, `Action::ListReplicas`,
`ReplicaAction::GetMany`) push tasks into via `spawn_local`, but
`run_async`'s `tokio::select!` had no `join_next` arm. Completed task
headers accumulate for the lifetime of the actor and only get released
when `abort_all()` runs at shutdown.
The fix adds the missing arm:
```rust
Some(res) = self.tasks.join_next(), if !self.tasks.is_empty() => {
if let Err(err) = res {
if !err.is_cancelled() {
warn!(?err, "actor reply-streamer task panicked");
}
}
continue;
}
```
This matches the canonical drain pattern used everywhere else in the
crate:
- `LiveActor::run_inner` drains three JoinSets in the same `select!`:
`running_sync_connect`, `running_sync_accept`, and `download_tasks`
(`src/engine/live.rs`).
- `GossipActor::progress` drains `active_tasks` with the same
`is_cancelled()` skip on `JoinError` (`src/engine/gossip.rs`).
`Actor::tasks` was the only `JoinSet` in the crate not following the
pattern. There is also a pre-existing TODO in `src/engine/live.rs` that
calls this out:
```
// TODO: abort_all and join_next all JoinSets to catch panics
```
The three `spawn_local` sites are kept as-is. `iter_to_irpc` is a
sync-iter → async-mpsc bridge that can stall on a slow consumer, so
inlining it would block the action queue (notably the `MAX_COMMIT_DELAY`
timeout flush). The fix lives entirely in the `select!`.
A regression test is added next to the existing `open_close` test in
`src/actor.rs::tests`. It fires 1000 calls of each streaming-reply shape
(3000 streamer tasks total), drains every reply stream to completion,
then asserts that `Actor::tasks` shrinks back to a small bound. Without
the new arm the residual is ~3000; with it the count drops to near zero
within tens of milliseconds. A `#[cfg(test)]`-gated
`Action::DebugTasksLen` and `SyncHandle::debug_tasks_len` provide the
introspection.
## Breaking Changes
None.
## Notes & open questions
The test introspection is `#[cfg(test)]`-only. Happy to instead expose a
public `wait_idle()`-style helper if you'd prefer that shape.
## Change checklist
- [x] Self-review.
- [x] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [x] Tests if relevant.
- [x] All breaking changes documented.1 parent 1f88013 commit b4f985d
1 file changed
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
| |||
514 | 520 | | |
515 | 521 | | |
516 | 522 | | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
517 | 530 | | |
518 | 531 | | |
519 | 532 | | |
| |||
661 | 674 | | |
662 | 675 | | |
663 | 676 | | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
664 | 685 | | |
665 | 686 | | |
666 | 687 | | |
| |||
702 | 723 | | |
703 | 724 | | |
704 | 725 | | |
| 726 | + | |
| 727 | + | |
705 | 728 | | |
706 | 729 | | |
707 | 730 | | |
| |||
1112 | 1135 | | |
1113 | 1136 | | |
1114 | 1137 | | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
1115 | 1194 | | |
0 commit comments