Skip to content

MHFU (ULUS10391): quest start drops everyone, host closes tcp-listen right after relay notifies it #4

Closed

Description

@kissofkill

Gathering Hall and chat work on a self-hosted relay (relay protocol 1, Ubuntu 22.04, Docker, Caddy HTTPS).
Metal Gear Solid: Peace Walker multipalyer works fine on the same relay.
However, when launching a multiplayer quest in MHFU, all players remain online in the gathering hall but are separated into solo quests upon starting, disconnecting exclusively from the host.

Firefox 158 WS captures during a failed quest start:

  • Host (tcp-listen, port 30001, backlog 3): receives one PT1 frame announcing a connection from the guest's virtual IP, sends nothing back, then the socket closes with code 1005.
  • Guest (tcp-connect, dst = host virtual IP, dstport 30001): receives no messages.

Relay log at the same moment:
{"event": "connection_closed", "mode": "tcp-connect", "reason": "[Errno 32] Broken pipe"}

No "no listener or accept backlog full" errors, so pairing succeeds.
It looks like the host side closes the listener immediately after the connection notice.
Happy to test patches or provide more logs.

Activity

  1. kissofkill commented on Oct 31, 2026

    @kissofkill
    Author

    Follow-up with a possible cause and a fix for the MHFU quest-start drop.

    Cause (as far as I can tell): MHFU closes its listening socket after it has accepted a connection. In adhoc-transport.js, ops.close on a listener calls ws.close() on the /tcp-listen WebSocket and marks all accepted children closed. Accepted connections are multiplexed over that one WebSocket, so the relay tears down the guest's /tcp-connect as well, which appears in the relay log as {"event": "connection_closed", "mode": "tcp-connect", "reason": "[Errno 32] Broken pipe"}. On a real PSP or a normal OS, closing a listener does not affect connections that were already accepted.

    Evidence: With a browser console log in ops.close, the failing run showed the listener being closed by the game (called from _fd_close). On the run that worked, the listener closed with 1 accepted connection and the quest stayed up.

    Fix: When a listener is closed while it still has accepted children, mark it closed so it accepts no more connections, drop only the not-yet-accepted ones, and keep the /tcp-listen WebSocket open until the last accepted child closes. Control socket teardown and disconnect() still close everything (__forceClose).

    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.
         };
    

    Testing so far: one pair of players, MHFU (ULUS10391), Firefox 158, self-hosted relay. After the change a quest started and ran. Please treat it as untested beyond that.

    Not fixed by this: when the host PC is very slow, the host sat on "preparing the quest" for about a minute, and the game closed the listener before any connection was accepted (accepted: 0). The guest still dropped in that case. That looks like a timing problem in the game, not this bug.

    Happy to test other changes or provide more logs.

  2. kissofkill commented on Oct 31, 2026

    @kissofkill
    Author

    Confirming: after updating to 990e875, MHFU (ULUS10391) quest start works for me. Two physical clients (desktop and laptop) connected through my self-hosted relay, started a quest and joined it, with no noticeable lag. Before the update, starting a quest dropped everyone back into the solo quest while being in the same gathering hall.

    The fix matches the cause I described in my report (the shared /tcp-listen WebSocket being closed together with the listener), and I'm glad the report helped and patch I sent helped.

    The slow-host case from my first report is still there. With a very slow PC as host, "preparing the quest" took about a minute and the guest dropped within seconds, with the listener closing before any connection was accepted. That looks like a separate timing problem, so I'm leaving it out of this issue unless you want it tracked here.

    I've opened #5 to add these test results to docs/multiplayer-validation.md. Thanks for the quick fix!

  3. root-hunter commented on Nov 1, 2026

    @root-hunter
    Owner

    Thanks a lot for the detailed testing and for your contribution!

    Great to hear that quest start and joining are now working correctly with two physical clients through the relay, without noticeable lag.

    The slow-host scenario does sound like a separate timing issue. Feel free to open a new issue for it so we can track and investigate it independently.

    Thanks also for opening #5 and documenting the multiplayer validation results. Your reports and patch have been really helpful in improving multiplayer support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions