Quality: Duplicate accept loop code across UDS and TCP listeners #93

Open
opened 2026-05-11 13:48:53 +00:00 by thabeta · 0 comments
Owner

Severity: Low

Location

crates/hero_aibroker_server/src/main.rs

Finding

accept_loop() (UDS) and tcp_accept_loop() (TCP) are nearly identical:

// Both have the same structure:
async fn accept_loop(uds: UnixListener, app: Router) -> Result<()> {
    loop {
        let (stream, _) = uds.accept().await?;
        tokio::spawn(async move {
            let io = hyper_util::rt::TokioIo::new(stream);
            let hyper_svc = hyper::service::service_fn(move |req| { ... });
            let _ = hyper::server::conn::http1::Builder::new()
                .serve_connection(io, hyper_svc).await;
        });
    }
}

Recommendation

  • Extract a generic accept loop that works with any AsyncRead + AsyncWrite + Send stream
  • Single implementation for both UDS and TCP
## Severity: Low ## Location `crates/hero_aibroker_server/src/main.rs` ## Finding `accept_loop()` (UDS) and `tcp_accept_loop()` (TCP) are nearly identical: ```rust // Both have the same structure: async fn accept_loop(uds: UnixListener, app: Router) -> Result<()> { loop { let (stream, _) = uds.accept().await?; tokio::spawn(async move { let io = hyper_util::rt::TokioIo::new(stream); let hyper_svc = hyper::service::service_fn(move |req| { ... }); let _ = hyper::server::conn::http1::Builder::new() .serve_connection(io, hyper_svc).await; }); } } ``` ## Recommendation - Extract a generic accept loop that works with any `AsyncRead + AsyncWrite + Send` stream - Single implementation for both UDS and TCP
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_aibroker#93
No description provided.