mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-08-27 12:39:50 +00:00
01ee2f46ece493110510b8d8b5ca019488f33f7a
A pc's UDP sockets register with the reactor, and its ICE/DTLS/SCTP pumps spawn on the runtime, that is current while `new` builds it. For a rustdesk controller that is io_loop's own `#[tokio::main(flavor = "current_thread")]` runtime, dropped the moment io_loop returns — so the pc outlived the only runtime able to drive its I/O, and the session-end close, merely spawned there, was never polled once. No DTLS close_notify left, and the peer waited out ICE decay (~25-30s in its log) where TCP delivers a FIN at once. Driving the close from somewhere else does not help: the sockets and pumps are already gone, so close() returns having swallowed every transport error without reaching the wire. Home the pc where it can outlive its caller instead. `new` runs its body on WEBRTC_RT, a lazy process-lifetime runtime, so every socket and background task belongs to it; `close_detached_with` spawns each close there as its own task — never cancelled, since a close cancelled after RTCPeerConnection::close latches `is_closed` is unretryable and strands the pc in SESSIONS, and never serialized, since close() has no deadline and one stalled pc would otherwise block every later session's teardown. Data-plane futures are still polled from caller runtimes; only the owning driver has to stay alive. A cancelled `new` needs the same care: rt.spawn keeps running when its JoinHandle is dropped, so the setup task would finish, cache the session, and hand its result to nobody — and an unanswered offerer never reaches a terminal ICE state, so it sat in SESSIONS forever. NewStreamHandoff closes an abandoned freshly-built stream, and hands a cache hit back disarmed: that one is shared with a live caller whose connection must survive this one's cancellation. Tests cover the production shapes: a session-end close from a thread with no runtime, an EOF-then-Drop double close, a close queued as the creating runtime is destroyed, and the cancelled-new handoff both ways. Two suite leaks surfaced on the way — streams dropped without close, polluting SESSIONS for every later test — and are fixed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016HV43uh1ztv6Wm5qi3Y1ne
Description
No description provided
Languages
Rust
100%