Repository navigation
fix(broker): run module control calls on the blocking pool - #107
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Comment |
Tiny Sweeper reviewReviewed head: FindingsNo active actionable findings. Resolved this pass
Verdict: Ready for maintainer review · Priority: none Diagnostics and supporting detailsFull summaryPull request purpose (title): fix(broker): run module control calls on the blocking pool. Tiny Sweeper completed its review; deterministic results follow. Review snapshot
Completeness: Complete What changedIn `impl Broker {` (crates/tinybus/src/broker.rs), the synchronous module-control dispatch clones the member, rebinds it as `let member = &member;` inside a `move` closure handed to `tokio::task::spawn_blocking`, awaits the handle, and maps a `JoinError` through `unwrap_or_else` to `Error::failed("module control call failed: {error}")`. The critique lane reports the load, GitHub load, rescan and list/get work moving to the blocking pool, with the `Reinitialize`/`Stop`/`Enable` arms still borrowing correctly and the stop/reinitialize async paths returning early before the spawn; the security lane notes the join error carries only the JoinError display, not the request body, and that admission still runs synchronously before the closure. In crates/tinybus/src/broker_module_control_tests.rs, `RecordingControl`'s load callback sleeps 1.5 s for a `slow.so` path, and the new test `a_slow_module_load_does_not_stall_other_bus_calls` exercises the non-stalling behavior on the single-threaded default test runtime. The intended behavior is that other connections keep being routed during a long module operation, and these calls now require a runtime with a blocking pool. Features
TestsNo supported feature-to-test mapping was produced. Test execution is not inferred. Before mergeNone. Agent review detailscritique
security
tests
commits
description
Evidence and run details
|
c048d27 to
250c009
Compare
LoadModule maps a library, LoadGithubModule downloads and verifies a release and RescanModules walks directories, all synchronously inside the broker's routing task. On a current-thread runtime that froze every other connection until the call returned; on a multi-thread runtime it pinned a worker. The synchronous module-control calls now run under spawn_blocking.
250c009 to
b713bba
Compare
|
Re tinysweeper's critical "Move the module body out of the Context capture": declining, because the premise is incorrect. |
|
@tinysweeper review |
Summary
The broker answers the synchronous module-control members (
LoadModule,LoadGithubModule,RescanModules,EnableModule, and the list/get reads) inside its async routing task.LoadModulemaps a library,LoadGithubModuledownloads and verifies a release (bounded by minutes of network budgets), andRescanModuleswalks directories. While one of them ran, the task's runtime thread was blocked: on a current-thread runtime every other connection's calls waited for it, and on a multi-thread runtime it pinned a worker.Fix
The synchronous arm of
module_methodnow runs undertokio::task::spawn_blocking. The admission check, the asyncStopModule/ReinitializeModulearms and the reply shapes are unchanged. A panicked or cancelled blocking task becomes a "module control call failed" error instead of tearing down the broker task.Validation
Regression test
a_slow_module_load_does_not_stall_other_bus_calls(in the module-control tests): on the default single-thread test runtime, one peer'sLoadModuleblocks for 1.5 s in the control callback while another peer callsListModules.cargo test -p tinybus --features modules --lib -- a_slow_module_load_does_not_stall_other_bus_calls:broker.rs)Ownership in the spawn_blocking closure
module_methodtakesbody: Valueby value (crates/tinybus/src/broker.rs:535), so themoveclosure handed tospawn_blockingtakes ownership of it and is'staticwith no copy. Onlymemberis borrowed (&MemberName), so it is cloned once before the closure and re-borrowed inside it (let member = &member;).Behaviour change
Other connections keep being routed while a module load, GitHub load or rescan runs. These calls now need a Tokio runtime with a blocking pool, which every runtime that serves the broker already has.