mirror of https://github.com/ospab/ostp.git
Matches a real user report after 2 weeks on this version: bandwidth is low, the client reconnects every 10-20 minutes, sites randomly stop loading or crawl, and ping visibly jitters. Root cause: the per-target-connection reader task (handle_relay_message's Connect handler) read from the upstream target as fast as it would send and forwarded every chunk straight to send_relay_to_stream -> an immediate UDP datagram, with ZERO awareness of the client-facing OSTP session's actual congestion window. The client already gates its own uplink on cwnd (bridge.rs's proxy_ev select arm); the server's download direction had no equivalent. On a real (lossy/jittery mobile or Wi-Fi) client path, a fast target (a CDN, say) gets blasted at the client far beyond what the path can sustain. That's a self-inflicted loss burst: it wrecks the RTT/RTO estimate (the "ping jitters" symptom), can push the session into a stall bad enough that the client's 25s/180s keepalive stall-detection gives up and reconnects (the "every 10-20 minutes" symptom), and produces exactly the "randomly stops loading or crawls" experience while it's happening. Fix: Dispatcher::snapshot_backpressure() computes each session's headroom (clamped cwnd - in_flight, same clamp(16,16384) the client uses) from the existing 10ms retransmit tick - no new polling loop. Published to a lock-free-reader Arc<AtomicI64> per session in a shared map so relay reader tasks (which don't have access to Dispatcher; it lives on the main loop task) can check it without touching a lock/mutex on every read. Before each read, a reader task waits (capped at 2s, so a wedged read can't stall forever) while headroom is <= 0. New sessions default to a healthy 32 packets until their first snapshot lands (worst case 10ms), so this can't stall the very first bytes of a fresh connection. Scoped to the primary TCP CONNECT/proxy path (the one actual web browsing uses); UDP relay/TURN is unaffected. No load test against real network jitter was possible in this environment - the mechanism directly targets the identified cause, but real-world confirmation is still needed. |
||
|---|---|---|
| .. | ||
| src | ||
| Cargo.toml | ||