a month ago
Hey Railway team! 👋
I'm having persistent WebSocket connection issues with my Reflex (Python web framework) app deployed
on Railway. The frontend loads perfectly, but WebSocket connections fail immediately.
Error Pattern:
✅ Frontend loads correctly
❌ WebSocket connection to wss://my-app.up.railway.app/_event fails
❌ Browser shows "101 Switching Protocols" response followed immediately by connection close
❌ Error: "WebSocket is closed before the connection is established"
What I've Tried:
Single PORT approach: Backend listening on $PORT environment variable
Backend-only deployment: Serving static frontend from backend on same port
Header simplification: Removed potentially problematic proxy headers
Debug logging: Enabled --loglevel debug but no websocket-specific errors shown
Current Configuration:
nixpacks.toml
[start]
cmd = 'reflex run --backend-only --env prod --backend-host 0.0.0.0 --backend-port $PORT'Key Details:
Backend starts successfully on Railway's PORT
/ping endpoint works fine (returns pong)
WebSocket server should be accessible at /_event
Same codebase works locally with websockets
Using Reflex 0.8.11 (Python web framework with Socket.IO-based websockets)
Questions:
Are there any Railway-specific WebSocket limitations I should know about?
Do I need special configuration for WebSocket upgrades?
Any suggestions for debugging WebSocket connection issues on Railway?
0 Replies
i believe i have everything set up properly on my app.
If you have any suggestions, i'd love to hear.
is localhost working with no issues?
I think your server lacks the upgrade header needed by websockets to work.
you need to proxy your server with one of these (nginx,caddy,traefik) so to alter the headers.