Reflex App WebSocket Connection Fails on Railway - "WebSocket is closed before connection..."
michael-lyon
FREEOP

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:

  1. Single PORT approach: Backend listening on $PORT environment variable

  2. Backend-only deployment: Serving static frontend from backend on same port

  3. Header simplification: Removed potentially problematic proxy headers

  4. 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:

  1. Are there any Railway-specific WebSocket limitations I should know about?

  2. Do I need special configuration for WebSocket upgrades?

  3. Any suggestions for debugging WebSocket connection issues on Railway?

$10 Bounty

0 Replies

irazvan2745
PRO

a month ago

are you sure its railway and not your app?


michael-lyon
FREEOP

a month ago

i believe i have everything set up properly on my app.
If you have any suggestions, i'd love to hear.


irazvan2745
PRO

a month ago

is localhost working with no issues?


michael-lyon
FREEOP

a month ago

yes


irazvan2745
PRO

a month ago

try with railpack


irazvan2745
PRO

a month ago

nixpacks is kinda deprecated


irazvan2745
PRO

a month ago

small chances that it will make a difference, but worth a shot


michael-lyon
FREEOP

a month ago

let me try to do that.


michael-lyon
FREEOP

a month ago

is it possible you share your sample with me?


irazvan2745
PRO

a month ago

?


michael-lyon
FREEOP

a month ago

railpack


irazvan2745
PRO

a month ago

just


irazvan2745
PRO

a month ago

configure it through the ui?


michael-lyon
FREEOP

a month ago

how do you do that?


irazvan2745
PRO

a month ago

railway ui?


coding-dynasty
PRO

a month ago

I think your server lacks the upgrade header needed by websockets to work.



coding-dynasty
PRO

a month ago

you need to proxy your server with one of these (nginx,caddy,traefik) so to alter the headers.


Loading...