Commit39fc7208Recorded14 Jul 2026Repositoryenclave

enclave-rpc: drop the browser-driver connecting-window workaround

Message

rpc-browser-poll no longer waits for the socket to be OPEN before draining; it drains unconditionally again (still gating registration on irc-ws-connected?, the required wait-open-before-NICK/USER handshake step). Polling a still- connecting socket is now safe because (sigil websocket) ws-receive returns #f during the async-open window instead of 'closed, so irc-ws-receive no longer latches the session dead before it opens. Reverts the f56c53b workaround now that the transport libraries distinguish CONNECTING from CLOSED at the source.

Changed
 packages/enclave-rpc/src/enclave/rpc/browser.sgl | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)
Diff
packages/enclave-rpc/src/enclave/rpc/browser.sglmodified
@@ -106,29 +106,23 @@
106
(let ((ws (rpc-browser-ws drv)))
107
(cond
108
((not ws) #f)
109
;; Not registered yet: WAIT for the browser socket to actually reach
110
;; OPEN before touching it. Draining a still-CONNECTING socket is
111
;; fatal — irc-ws-receive treats a not-yet-open socket as 'closed and
112
;; permanently marks the session disconnected (a slow-open race:
113
;; harmless on localhost, where the socket opens before the first
114
;; poll, but it kills every higher-latency connect, e.g. over a VPN
115
;; or a real network). So only register (and only then begin
116
;; draining) once the socket is genuinely OPEN.
117
;;
118
;; NOTE: this guard is a WORKAROUND for a bug in the transport
119
;; libraries — sigil-websocket `ws-receive` returns 'closed for a
120
;; still-CONNECTING socket and sigil-irc-websocket `irc-ws-receive`
121
;; then latches the session to 'disconnected. Once that is fixed at
122
;; the source (distinguish CONNECTING from CLOSED — see the
123
;; ws-receive-connecting-vs-closed follow-up), this special case can
124
;; be removed and the poll can drain unconditionally again.
125
((not (rpc-browser-registered drv))
126
(when (irc-ws-connected? ws)
+109
(else
+110
;; Send NICK/USER once, when the browser socket is really OPEN.
+111
;; irc-ws-connect optimistically reports `open` before the browser
+112
;; socket finishes connecting, so gate registration on
+113
;; irc-ws-connected? (the transport-spike ★ handshake finding) —
+114
;; sending before OPEN drops the registration frames.
+115
(when (and (not (rpc-browser-registered drv))
+116
(irc-ws-connected? ws))
117
(set-rpc-browser-registered! drv #t)
118
(irc-ws-register ws))
129
#t)
130
;; Registered (socket has been OPEN): drain inbound frames.
131
(else
+119
;; Drain inbound frames unconditionally. Polling a still-CONNECTING
+120
;; socket is safe: (sigil websocket) ws-receive now returns #f (not
+121
;; 'closed) during the async-open window, so irc-ws-receive no longer
+122
;; latches the session dead before it opens (fixed at the source —
+123
;; sigil-wasm-net readyState accessor + ws-receive CONNECTING/CLOSED
+124
;; split; see ws-receive-connecting-vs-closed). This replaces the
+125
;; former wait-for-OPEN-before-draining workaround (commit f56c53b).
126
(let loop ((n 0) (live #t))
127
(if (or (>= n budget) (not live))
128
live