mirror of https://github.com/ospab/ostp.git
Root cause of "constantly disconnects on mobile, have to reconnect manually": Android's ConnectivityManager fires onLost(old) + onAvailable(new) within milliseconds of each other during a real Wi-Fi<->cellular handoff, and each one queues its own BridgeCommand::NetworkChanged. Each reconnect is a full sequential handshake (up to ~1.2s x 4 attempts x mux_sessions) run synchronously inside the bridge's select-loop iteration - so without coalescing, the FIRST queued NetworkChanged often starts reconnecting before the OS has actually finished switching networks, races the dying interface, and only fails after burning its full attempt budget. Only THEN does the SECOND (correct) NetworkChanged get to run its own reconnect. A sub-second handoff was turning into several extra seconds of outage on every occurrence, and multiple back-to-back handoffs (common walking in/out of Wi-Fi range) compounded this every time. Fix: on NetworkChanged, drain any additional same-kind events already queued before starting the reconnect, so a burst collapses into one attempt using the freshest signal. A different command found while draining isn't dropped - it's dispatched immediately (recursing into handle_bridge_cmd) so nothing queued behind the burst gets lost or reordered incorrectly. |
||
|---|---|---|
| .. | ||
| src | ||
| Cargo.toml | ||
| test_udp.rs | ||