I am using socket.io with node.js on Heroku. Everything seems to work. However, in the Chrome dev bar, I get Unexpected response code: 503
. Does anyone know what this could mean? Should I be concerned about it? Will it take up memory in the browser? And if so, can I suppress it?
Heroku "doesn't support" websockets on the Cedar stack yet (no word on when they will) Update: see below. They recommend adding the following code to your Socket.io implementation:
// assuming io is the Socket.IO server object
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
The reason for this is that Heroku adds a routing layer on top of your dynos. Your code will be executed on a server, but it's non-deterministic as to which server it will be. Thus, WebSockets can't send data to the "correct" server. Socket.IO will downgrade to long-polling, which keeps the connection alive through the routing layer, ensuring that the events will be executed on the correct server.
UPDATE: Heroku WebSockets is now in public beta! You can add WS support to your app by executing heroku labs:enable websockets -a myapp
in your app directory.
For people coming from google in 2016.
Heroku websockets are now supported, no need to turn them on. WebSockets on Heroku
Make sure to check your logs on Heroku. I noticed the 503 error happen in chrome and after checking logs, turned out that my Heroku app had crashed. There was a bug in my code which caused it to not responding (not socket.io related at all)
Fixed the code and 503 went away!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With