From 92d99bed1ff726c392365c589f54bd446b0cbe75 Mon Sep 17 00:00:00 2001 From: kissofkill Date: Fri, 30 Oct 2026 23:26:31 -0500 Subject: [PATCH 1/3] Keep accepted PTP connections alive when the listener closes --- wasm-page/public/adhoc-transport.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/wasm-page/public/adhoc-transport.js b/wasm-page/public/adhoc-transport.js index 180bd61..5239263 100644 --- a/wasm-page/public/adhoc-transport.js +++ b/wasm-page/public/adhoc-transport.js @@ -138,7 +138,7 @@ const id = new DataView(data.buffer, data.byteOffset).getUint32(4); if (data[3] === 1) { const n = data[8]; if (n < 7 || n > 15 || data.length !== n + 11) throw new Error('Invalid PTP open'); - if (sock.pending.length >= sock.__backlog) { safeSend(sock, sock.__relay.ws, stream(3, id)); return; } + if (sock.__closed || sock.pending.length >= sock.__backlog) { safeSend(sock, sock.__relay.ws, stream(3, id)); return; } const child = SOCKFS.createSocket(sock.family, sock.type, sock.protocol); child.__ppssppAdhoc = true; child.saddr = localIP; child.sport = sock.sport; @@ -280,23 +280,36 @@ }; ops.close = function(sock) { if (!cfg.enabled || !sock.__ppssppAdhoc) return original.close(sock); + if (sock.server && sock.__accepted && sock.__accepted.size > 0 && !sock.__forceClose && !sock.__listenClosed) { + sock.__closed = true; sock.__listenClosed = true; + for (const c of [...sock.pending]) { + c.__closed = true; + try { safeSend(sock, sock.__relay?.ws, stream(3, c.__connId)); } catch (_) {} + sock.__accepted.delete(c.__connId); sockets.delete(c); SOCKFS.emit('close', c.stream.fd); + } + sock.pending = []; + if (sock.__accepted.size > 0) { publish(); return 0; } + } sock.__closed = true; if (sock.__parent) { try { safeSend(sock, sock.__parent.__relay?.ws, stream(3, sock.__connId)); } catch (_) {} sock.__parent.__accepted.delete(sock.__connId); + const parent = sock.__parent; + if (parent.__listenClosed && parent.__accepted.size === 0) { parent.__relay?.ws?.close(); sockets.delete(parent); } } sock.__relay?.ws?.close(); for (const child of sock.__accepted?.values() || []) { child.__closed = true; SOCKFS.emit('close', child.stream.fd); } sock.__accepted?.clear(); sock.recv_queue.length = 0; sockets.delete(sock); if (sock === control) { registered = false; control = null; stats.state = 'disconnected'; stats.game = ''; stats.group = ''; peers.clear(); + for (const s of sockets) s.__forceClose = true; for (const s of [...sockets]) ops.close(s); } publish(); return 0; }; const api = { snapshot() { publish(); return { ...stats }; }, - disconnect() { for (const s of [...sockets]) ops.close(s); }, + disconnect() { for (const s of sockets) s.__forceClose = true; for (const s of [...sockets]) ops.close(s); }, destroy() { api.disconnect(); globalThis.removeEventListener?.('pagehide', api.disconnect); clearInterval(timer); for (const [name, fn] of Object.entries(original)) ops[name] = fn; delete ops.__ppssppRelayInstalled; }, // Reconnect follows the HLE lifecycle: leave multiplayer and re-enter it. }; From b9958491970e87830d6d04920d838b5f57cb82c0 Mon Sep 17 00:00:00 2001 From: kissofkill Date: Sat, 31 Oct 2026 03:11:20 -0500 Subject: [PATCH 2/3] Add test results for MHFU quest start with remote relay Documented test results for MHFU quest start using a remote relay, highlighting improvements and known limitations post-fix. --- docs/multiplayer-validation.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/multiplayer-validation.md b/docs/multiplayer-validation.md index da8b159..7b3031e 100644 --- a/docs/multiplayer-validation.md +++ b/docs/multiplayer-validation.md @@ -76,3 +76,20 @@ A quest with two MHFU clients, Firefox and a remote relay remains to be checked. The separately reported slow-host timeout before any connection is accepted is outside this fix. Publish the rebuilt web shell to deliver the change; the emulator core and relay do not need rebuilding for this JavaScript correction. + +### MHFU quest start on a remote relay (community test) — 2026-10-31 + +**Result: with 990e875, MHFU (ULUS10391) quest start works.** Two physical clients connected through a remote relay, started a quest and joined it, with no noticeable lag. Before the listener fix (#4), starting a quest dropped every player back into solo quest while still being in the same gathering hall instance. + +Setup: Firefox 158 on Windows, self-hosted relay on an Oracle VM behind Caddy with trusted TLS (relay protocol 1, Docker). The failing runs used two players on separate internet connections. The run with 990e875 used one tester's desktop and laptop, both connecting to the remote relay. + +Before the fix: +- Starting a quest dropped everyone back into a solo quest instance, while the gathering hall, lobby and chat worked. +- The relay logged `{"event": "connection_closed", "mode": "tcp-connect", "reason": "[Errno 32] Broken pipe"}`, with no "no listener or accept backlog full" errors. +- Browser WebSocket captures showed the host's `/tcp-listen` (port 30001, backlog 3) receiving one PT1 connection notice and then closing with code 1005, while the guest's `/tcp-connect` received no frames. +- A local patch with the same behavior (keep the shared listener WebSocket open while accepted streams exist) also let a quest start and run. + +After the fix (990e875): +- Quest started, and host and guest connected and played, with no noticeable lag. + +Known limitation: with a slow host PC, "preparing the quest" lasted about a minute and the guest dropped within seconds. The listener closed with 0 accepted connections, so this is the timing case outside the listener fix. Player with the fastest PC should be the host. From a896e6f6b2ce56475c39b2e7d97c7f43adb7c184 Mon Sep 17 00:00:00 2001 From: kissofkill Date: Sat, 31 Oct 2026 03:15:51 -0500 Subject: [PATCH 3/3] Simplify socket close operation logic Removed complex closing logic for accepted connections in the socket operations. --- wasm-page/public/adhoc-transport.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/wasm-page/public/adhoc-transport.js b/wasm-page/public/adhoc-transport.js index b540ae2..7fb84b7 100644 --- a/wasm-page/public/adhoc-transport.js +++ b/wasm-page/public/adhoc-transport.js @@ -298,16 +298,6 @@ }; ops.close = function(sock, force = false) { if (!cfg.enabled || !sock.__ppssppAdhoc) return original.close(sock); - if (sock.server && sock.__accepted && sock.__accepted.size > 0 && !sock.__forceClose && !sock.__listenClosed) { - sock.__closed = true; sock.__listenClosed = true; - for (const c of [...sock.pending]) { - c.__closed = true; - try { safeSend(sock, sock.__relay?.ws, stream(3, c.__connId)); } catch (_) {} - sock.__accepted.delete(c.__connId); sockets.delete(c); SOCKFS.emit('close', c.stream.fd); - } - sock.pending = []; - if (sock.__accepted.size > 0) { publish(); return 0; } - } sock.__closed = true; // Accepted PTP streams share the listener's WebSocket, but own their // lifetime. Closing the listening fd only rejects unaccepted connections.