2 months 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:
Custom domain configuration - Added the domain via Railway's Custom Domain feature
CORS configuration - Set
origin: "*"in Socket.io server configTransport order testing - Tried both
['polling', 'websocket']and['websocket', 'polling']Timeout adjustments - Set
pingTimeout: 60000ms,pingInterval: 25000msto match Railway's 60s keep-aliveServer binding - Confirmed server binds to
0.0.0.0on Railway'sPORTenvironment 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?
1 Replies
2 months 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!