WebSockets issue connecting to Node Express App

I have a Node Express App which I’ve deployed according to the docs. The server has a WebSocket endpoint and everything works fine locally. When we deploy the app it is hit and miss whether we can connect to the server via our one-page app (also deployed to Render). The error we see in the browser console is:

WebSocket connection to 'wss://chat-server-a1mm.onrender.com/chat' failed: WebSocket is closed before the connection is established

When we run our one-page app locally and connect to the server we see the same error. Deploying the Express App to a Droplet and connecting to it everything works fine. We deployed the app as a Docker container to see if it behaves any differently but we got the same result.

Are there any other settings we need to enable to get WebSockets to work more reliably? Any suggestions on how to debug this further? At the moment it feels like the issue is between our deployed Express App and the load balancer (or proxy) in front of it.

Hi @croman,

Sorry we missed your question earlier. Are you still running into issues?

Yeah, still having issues with it. You can see if it happening if you go to https://lodestar.cliche.cloud/ and open the console. After a minute or two you’ll see the error message. Still stumped as to why it is happening.

Hi @croman,

I looked into your issue. I was able to verify that the error is showing up in the console when I open the link you posted. There’s no settings needed to make WebSockets work for apps deployed on Render.

According to this StackOverflow post I found, can you take a look at how you’re establishing the WebSocket connection? Potentially, close() might be called before the connection is established. One experiment you could do is move the close() call to a different location or initially omit it altogether to see if the same error is occurring.

I’ll have a look at it and see if makes things better. The strange problem is that the exact same stack deployed locally or to a droplet on DigitalOcean all works fine. Makes me think there might be something happening at the proxy level directing traffic to our app.

That’s definitely strange that it works fine deployed to a droplet on DigitalOcean.

If the issue doesn’t go away, would you mind creating a minimal repro that we can use to investigate? An express app with a single websocket endpoint and a one-page app that only tries to connect to that endpoint would be ideal.

@croman did you get this figured out?

Interested here too!

I’m getting similar connection issues with Actionhero (GitHub - actionhero/actionhero: Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks) and getting basically the same error `ActionheroWebsocketClient.js:3657 WebSocket connection to

ActionheroWebsocketClient.js:3657 WebSocket connection to 'wss://demo-actionherojs-com.onrender.com/primus?sessionID=1def3d71256d7f2a4c90cb3c6241b055dd08bad9&_primuscb=NrAzOfq' failed: 
opening @ ActionheroWebsocketClient.js:3657
emit @ ActionheroWebsocketClient.js:352
open @ ActionheroWebsocketClient.js:3201
open @ ActionheroWebsocketClient.js:2639
tickedtock @ ActionheroWebsocketClient.js:1589
chat.html:87 error Error
    at Primus.error (https://demo-actionherojs-com.onrender.com/public/javascript/ActionheroWebsocketClient.js:2889:13)
    at Primus.emit (https://demo-actionherojs-com.onrender.com/public/javascript/ActionheroWebsocketClient.js:332:35)
    at WebSocket.emitter (https://demo-actionherojs-com.onrender.com/public/javascript/ActionheroWebsocketClient.js:112:22)

For what it’s worth, these same settings work out of the box on Heroku

Interested here too!

I’m getting similar connection issues with Actionhero (GitHub - actionhero/actionhero: Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks) and getting basically the same error `ActionheroWebsocketClient.js:3657 WebSocket connection to

ActionheroWebsocketClient.js:3657 WebSocket connection to 'wss://demo-actionherojs-com.onrender.com/primus?sessionID=1def3d71256d7f2a4c90cb3c6241b055dd08bad9&_primuscb=NrAzOfq' failed: 
opening @ ActionheroWebsocketClient.js:3657
emit @ ActionheroWebsocketClient.js:352
open @ ActionheroWebsocketClient.js:3201
open @ ActionheroWebsocketClient.js:2639
tickedtock @ ActionheroWebsocketClient.js:1589
chat.html:87 error Error
    at Primus.error (https://demo-actionherojs-com.onrender.com/public/javascript/ActionheroWebsocketClient.js:2889:13)
    at Primus.emit (https://demo-actionherojs-com.onrender.com/public/javascript/ActionheroWebsocketClient.js:332:35)
    at WebSocket.emitter (https://demo-actionherojs-com.onrender.com/public/javascript/ActionheroWebsocketClient.js:112:22)

For what it’s worth, these same settings work out of the box on Heroku.

The demo server us up at https://demo-actionherojs-com.onrender.com (click on “Real Time Chat”)

Hello Evan,

I took a look at your service and tried deploying an Action Hero of my own at: https://actionhero-test.onrender.com/ and was able to have to get it successfully running without the web socket errors.

A few things to try:

  1. Set your build command to: npm install && npm run build
  2. Set your start command to: npm run start
  3. Probably un related but it seems that your Redis instance ended up running on port 10000 instead of 6379. Can you add an environment variable to that service PORT: 6379 which will force Redis to redeploy and use that port.

Let me know if you still have issues.

Thanks for the feedback @Sean_Doughty!
I can see the app building and starting OK in the logs, and I can confirm that it’s properly connected to redis (the app crashes and doesn’y boot otherwise). The REST api parts of the app all work OK (eg Actionhero.js Swagger Documentation).

When checking out your version, I see quite a few problems with the API (nothing loaded on the homepage for instance).

I’m curious if the deployment type matters - I did a web service


This is going to sound nuts - but I’m pretty sure that the new versions of the app I’m deploying are not what’s being served up on https://demo-actionherojs-com.onrender.com/. The logs don’t show any requests, and they should.

Can you correlate a deployment with a URL?


(I’m not allowed to post more comments, so I keep editing this one)

Hello Evan,

We removed the mute from your account you should be able to add more replies.

When you say homepage do you mean: https://actionhero-test.onrender.com/ because that is loading correctly for me.

Web service is correct, did you try changing your build & start commands as specified?

I double checked your deployment and I can see that your deployment is using the latest git commit on your repo.

Hello Evan,

I was able to replicate the error you are having when using the Free plan. We are taking a look to see why this is the case.

Update:
We are looking at why the web sockets are not working with our Free Plan and we will pick up this thread early next week. In the meantime, you could try running your api on the Starter plan.

1 Like

I’m getting the same issue with my Phoenix app too where LV can’t connect. Thanks for looking into this!

Yep! It works on the starter plan!

Thanks for the suggestions all (and this Twitter thread https://twitter.com/fmterrorf/status/1463341413446262793?s=21)

Yeah I’m also getting this on Phoenix. Works flawlessly with a local release but when deployed I get an error. Everything else on the platform is working well.

I can confirm that sockets fail on the free plan but work on the Starter. Phoenix

Hi folks, we’ve resolved the issue with websockets on the free plan. Apologies for any inconvenience here!