WebTransport: datagrams.writable write() promises never settle when the session closes concurrently; maxDatagramSize stays 0 (parent drops OutgoingDatagram/GetMaxDatagramSize resolvers on closed sessions)
Categories
(Core :: Networking, defect)
Tracking
()
People
(Reporter: jeon1691, Unassigned)
Details
User impact: A page using WebTransport datagrams can get wt.datagrams.writable.getWriter().write() promises that NEVER settle when the session is closed (by the server, or connection loss) while datagrams are in flight. Because WritableStream serializes writes, the first never-settling write blocks every subsequent write() behind it — the page's datagram path is permanently stuck. Additionally, if the session closes right after establishment, wt.datagrams.maxDatagramSize stays 0 forever, which makes all subsequent write() calls resolve without ever sending the datagram (silent discard).
Spec: the write-datagrams algorithm resolves the write promise even when a datagram is discarded (https://w3c.github.io/webtransport/#write-datagrams — the in-code comment at dom/webtransport/api/WebTransportDatagramDuplexStream.cpp:365-368 explicitly acknowledges this).
Source chain (Nightly 160.0a1, 2026-10-21, mozilla-central):
-
Child: the write() promise settles ONLY through the PWebTransport OutgoingDatagram IPC resolver:
-
Parent: WebTransportParent::RecvOutgoingDatagram (dom/webtransport/parent/WebTransportParent.cpp:1178-1210) stores the resolver in the single slot mOutgoingDatagramResolver, calls mWebTransport->SendDatagram(...) with the return value IGNORED, and relies on a comment asserting the outcome callback fires synchronously. That assumption fails on four state-guarded paths that return without ever invoking the callback (session no longer ACTIVE):
- netwerk/protocol/webtransport/WebTransportSessionProxy.cpp:779-782 SendDatagram: state != ACTIVE / no session -> NS_ERROR_NOT_AVAILABLE, no callback
- netwerk/protocol/http/Http3WebTransportSession.cpp:563-565 SendDatagram: mSendState != PROCESSING_DATAGRAM -> plain return
- netwerk/protocol/http/Http3WebTransportSession.cpp:716-718 OnOutgoingDatagramOutCome: mRecvState != ACTIVE / !listener -> return
- netwerk/protocol/webtransport/WebTransportSessionProxy.cpp:1672-1674 OnOutgoingDatagramOutComeInternal: mState != ACTIVE / !mListener -> return
Consequences: (a) the child's write() promise never settles (permanent hang, queue-blocking); (b) the next RecvOutgoingDatagram overwrites mOutgoingDatagramResolver, dropping the previous resolver (MOZ_ASSERT(!mOutgoingDatagramResolver) is a no-op in release); (c) small per-resolver leak.
-
Same pattern for mMaxDatagramSizeResolver in RecvGetMaxDatagramSize (WebTransportParent.cpp:1143-1156, rv also ignored): on a session that is closed right after establishment, the GetMaxDatagramSize response never reaches WebTransportDatagramDuplexStream::SetMaxDatagramSize, so wt.datagrams.maxDatagramSize keeps its initial/reset value (observed 0) instead of the negotiated size.
-
Contrast: GetStats resolvers ARE settled on every close path (RecvClose / OnSessionClosed / NotifyRemoteClosed / ResolvePendingGetStats) — the datagram resolvers appear to have been missed when that handling was added.
Steps to reproduce (runtime-verified on Nightly ASan 160.0a1 2026-10-21 build 0fdb388b, Linux, default prefs network.webtransport.enabled=true):
Setup: local HTTP/3 WebTransport server (aioquic-based WPT tools/webtransport server with one addition: also advertise SETTINGS_ENABLE_WEB_TRANSPORT 0x2b603742=1, which current nightly requires from the server) with an ECDSA localhost cert accepted via the serverCertificateHashes option, and handlers: /echo.py (datagram echo), /close.py (accepts, then closes the session 600ms later), /close_immediately.py (closes at establishment). Test page served over http://127.0.0.1 (loopback = secure context).
Test A — write() hang:
const wt = new WebTransport("https://127.0.0.1:4433/close.py?ms=600", {serverCertificateHashes:[...]});
await wt.ready;
const w = wt.datagrams.writable.getWriter();
loop every 5ms: w.write(new Uint8Array([i]));
await wt.closed; // resolves when the server close lands
keep writing for another ~700ms; then check which write promises settled.
Observed: sent=200, resolved=71, rejected=0, HUNG=129 — the write in flight when the close landed (idx 71) and ALL subsequent writes never settle, still pending 15s later (and indefinitely — every later write queues behind the never-settling sink promise). Control: identical loop against /echo.py with a client-side wt.close() afterwards — no hang (writes resolve).
Test B — maxDatagramSize never updates:
const wt = new WebTransport("https://127.0.0.1:4433/close_immediately.py", {serverCertificateHashes:[...]});
await wt.ready; // resolves
await wt.closed; // resolves (clean server close)
wt.datagrams.maxDatagramSize // == 0, forever
Observed 6/6 rounds: maxDatagramSize stays 0 (checked immediately and +1.2s). Baseline healthy session: 1224. Since the attribute is 0, WriteCallbackImpl step 4 (WebTransportDatagramDuplexStream.cpp:338-343) early-resolves every subsequent write without sending — datagrams are silently discarded.
MOZ_LOG=WebTransport:5 confirms the child sends the datagram ("Sending Datagram, size = 1") but never logs "Datagram was sent" for the affected writes; on the parent side the OutgoingDatagram resolver is never invoked after the session leaves ACTIVE.
Suggested fix: settle (or reject) mOutgoingDatagramResolver and mMaxDatagramSizeResolver on every session-close path, mirroring the existing GetStats handling — e.g. when the session is not ACTIVE, resolve the pending datagram resolver with the drop outcome (spec: "resolve undefined when the datagram is discarded") and cache/deliver the negotiated max datagram size (or reject it) instead of leaving the slots permanently occupied. A guard in WriteCallbackImpl re-checking the transport state would additionally prevent queueing writes into a dead sink.
Comment 1•1 month ago
|
||
~45 WebTransport patches landed in the last week; the main issues here all appear to be resolved. Retest, if there are still issues please file new bugs. Thanks!
| Reporter | ||
Comment 2•1 month ago
|
||
Thanks - retested both issues from this report on current Nightly with the same harness as the original report (local aioquic WPT WebTransport server + serverCertificateHashes).
Nightly 161.0a1, BuildID 20261022214940, changeset bbbd29a03fc7, neqo-http3 0.33.0, Linux:
-
datagrams.writable write() settling on session close with in-flight datagrams: FIXED. Server closes mid-cadence: sent=229, resolved=98, rejected=131, hung=0 (rechecked +17 s: still 0 hung) - the in-flight and queued writes now reject instead of hanging forever. Control on the original-report build (160.0a1, BuildID 20261019073400, changeset 0fdb388b) with the identical harness still reproduces the original behavior: sent=220, resolved=96, rejected=0, hung=124, still hung at +21 s.
-
maxDatagramSize after immediate post-establishment close: STILL REPRODUCES. 6/6 rounds: ready resolves, closed resolves cleanly, maxDatagramSize == 0 both immediately and +1200 ms later, forever (healthy-session baseline on the same build: 1224). Identical 6/6 on the old build.
Filed the residual as bug 2085220 per your instruction. Source at bbbd29a03fc7 in short: the clean-close handler (dom/webtransport/api/WebTransport.cpp, step 12.2) explicitly force-resolves ready when the connection closes before maxDatagramSize is received, but the datagrams duplex never receives a size on that path; and the RecvGetMaxDatagramSize resolver is still dropped when the session is not ACTIVE (WebTransportSessionProxy::GetMaxDatagramSize returns NS_ERROR_NOT_AVAILABLE, rv ignored), with no close path settling it (unlike GetStats via ResolvePendingGetStats).
Description
•