Socket.io WebSocket upgrade fails on Railway despite custom domain - polling works fine

atbreb
PROOP

a month ago

I'm running a Socket.io server (v4) on Railway with a custom domain. Socket.io connections work perfectly via polling transport, but WebSocket upgrades consistently fail.

What we're trying to accomplish: Enable WebSocket transport for Socket.io real-time notifications to reduce latency and improve efficiency.

What we've tried:

  1. Custom domain configuration - Added the domain via Railway's Custom Domain feature

  2. CORS configuration - Set origin: "*" in Socket.io server config

  3. Transport order testing - Tried both ['polling', 'websocket'] and ['websocket', 'polling']

  4. Timeout adjustments - Set pingTimeout: 60000ms, pingInterval: 25000ms to match Railway's 60s keep-alive

  5. Server binding - Confirmed server binds to 0.0.0.0 on Railway's PORT environment variable

Results:

Polling transport: Works perfectly - real-time updates delivered successfully
WebSocket upgrade: Fails silently - requests reach our server with proper headers but handshake never completes

Server logs show:

๐Ÿ”ด [REALTIME] Connection request: {
  url: '/socket.io/?EIO=4&transport=websocket',
  headers: {
    upgrade: 'websocket',      โœ… Present
    connection: 'Upgrade',     โœ… Present  
    origin: 'https://www.[custom-domain].com'
  }
}

But no Socket.io Engine.IO connection is established for WebSocket (whereas polling connections complete successfully).

Browser shows:

WebSocket connection to 'wss://[custom-domain].com/socket.io/?EIO=4&transport=websocket&sid=...' failed

Question: Is there additional Railway-specific configuration needed to enable WebSocket handshake completion, or does Railway's HTTP proxy have limitations that prevent Socket.io WebSocket upgrades even with custom domains?

$20 Bounty

1 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


Loading...
Socket.io WebSocket upgrade fails on Railway despite custom domain - polling works fine - Railway Help Station