Skip to content

Gateway self-probe fails under WSL2 mirrored networking (networkingMode=mirrored) #53877

@aderius

Description

@aderius

Description

The gateway fails to start when WSL2 is configured with networkingMode=mirrored in .wslconfig. It enters an infinite crash loop with the error:

Gateway failed to start: another gateway instance is already listening on ws://127.0.0.1:18789

Environment

  • OS: Windows 11 + WSL2 (Ubuntu)
  • OpenClaw: 2026.3.22 (4dcc39c)
  • Node.js: v22.22.0
  • WSL config: networkingMode=mirrored in C:\Users\<user>\.wslconfig

Root Cause

The gateway startup sequence:

  1. Binds the canvas HTTP server on the configured port (e.g., 18789) — succeeds
  2. Probes ws://127.0.0.1:18789 via WebSocket to check for competing gateway instances
  3. Under mirrored networking, this probe routes through the Windows network stack instead of staying within WSL loopback
  4. The probe hits the gateway's own canvas HTTP server (which is already bound but not yet serving WebSocket)
  5. Receives a non-WebSocket HTTP response
  6. Concludes another gateway instance is running → aborts startup

Reproduction

  1. Enable mirrored networking in .wslconfig:
    [wsl2]
    networkingMode=mirrored
  2. wsl --shutdown and reopen WSL
  3. Start the OpenClaw gateway: openclaw gateway start
  4. Observe crash loop in journalctl --user -u openclaw-gateway

Confirmation

  • Tested on an alternate port (18800) — same failure, proving no external process is involved
  • The gateway is detecting itself through the mirrored network path
  • ss -tlnp and lsof show no competing process on the port
  • Disabling mirrored networking resolves the issue immediately

Workaround

Comment out networkingMode=mirrored in .wslconfig and restart WSL. This forces WSL2 back to NAT mode where loopback stays within the Linux network namespace.

Suggested Fix

The self-probe should either:

  • Bind the WebSocket listener before probing, so the probe hits the actual WS endpoint
  • Use a different mechanism to detect competing instances (e.g., PID file, named socket, or flock)
  • Skip the WS probe when the canvas HTTP server was just bound by the current process
  • Add a short delay or retry with WS-specific validation before concluding another instance exists

Impact

WSL2 mirrored networking is increasingly common (it simplifies localhost sharing between Windows and WSL). This bug forces users to disable a useful networking feature to run OpenClaw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions