Background
Identified during code review of #128 (Define local daemon observability).
In crates/weaverd/src/dispatch/handler/mod.rs, route_request calls self.backends.with_backends(|backends| self.router.route(&request, writer, backends)). The with_backends closure holds the FusionBackends Mutex lock for the duration of the route call, which includes writing the response back to the client via ResponseWriter. Holding the lock during I/O operations increases lock-contention latency under concurrent connections and has no documented upper bound on hold duration.
No tests currently verify concurrent connection handling or lock behaviour under variable I/O latency.
Proposed direction
Refactor route_request to release the BackendManager lock before writing responses. Obtain the routing result inside the lock, then perform all ResponseWriter calls outside it. Add concurrent connection tests that verify correct behaviour and acceptable latency under variable I/O conditions. Document the intended maximum lock-hold duration as a constraint on the with_backends contract.
Affected files
crates/weaverd/src/dispatch/handler/mod.rs
crates/weaverd/src/dispatch/backend_manager.rs
- Test files under
crates/weaverd/src/tests/
References
Background
Identified during code review of #128 (Define local daemon observability).
In
crates/weaverd/src/dispatch/handler/mod.rs,route_requestcallsself.backends.with_backends(|backends| self.router.route(&request, writer, backends)). Thewith_backendsclosure holds theFusionBackendsMutexlock for the duration of theroutecall, which includes writing the response back to the client viaResponseWriter. Holding the lock during I/O operations increases lock-contention latency under concurrent connections and has no documented upper bound on hold duration.No tests currently verify concurrent connection handling or lock behaviour under variable I/O latency.
Proposed direction
Refactor
route_requestto release theBackendManagerlock before writing responses. Obtain the routing result inside the lock, then perform allResponseWritercalls outside it. Add concurrent connection tests that verify correct behaviour and acceptable latency under variable I/O conditions. Document the intended maximum lock-hold duration as a constraint on thewith_backendscontract.Affected files
crates/weaverd/src/dispatch/handler/mod.rscrates/weaverd/src/dispatch/backend_manager.rscrates/weaverd/src/tests/References