Eva
Eva

Reputation: 4690

400, 502, 503 errors with Websockets

I am making a multiplayer game using Socket.io, Node.js, and Openshift. It was working for a while, but I made a few small changes and now something unrelated to what I changed has broken. When a second player tries to join the game, it boots everyone out, showing a 503 error for anyone else who goes on the site. For the second player, I get a lot of console errors including

WebSocket connection to 'ws://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=websocket&sid=d5smykffy4EWHxgIAAAC' failed: Error during WebSocket handshake: Unexpected response code: 400

http://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=polling&t=1421020862973-4&sid=d5smykffy4EWHxgIAAAC Failed to load resource: the server responded with a status of 502 (Bad Gateway)

http://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=polling&t=1421020865831-6&sid=d5smykffy4EWHxgIAAAC Failed to load resource: the server responded with a status of 503 (Service Unavailable)

socket.io-1.2.0.js:2 WebSocket connection to 'ws://avalon-evao.rhcloud.com/socket.io/?EIO=3&transport=websocket&sid=c-fwcJaMkp_9rl5CAAAA' failed: WebSocket is closed before the connection is established.

It works perfectly fine in localhost, but the real site is broken.

Here's what I've tried:

  1. Using HTTPS. I still somehow get the 502 error.
  2. Restarting the app using rhc app restart
  3. Restarting the app using rhc app force-stop rhc app start
  4. Checking the memory limit. I haven't hit it.
  5. Connecting to websockets securely using the { secure: true } option

What is causing these errors and how can I fix them?

Upvotes: 2

Views: 5554

Answers (2)

Eva
Eva

Reputation: 4690

It turns out I was looking at the logs wrong. When I figured out how to read the logs for rhc, I found an error in the database. I had changed the structure of the collections without dropping the database, so there were indexes to keys that no longer existed. Dropped the database, and the app works fine now.

Upvotes: -1

user32
user32

Reputation: 177

Try:
ws://...rhcloud.com:8000/socket.io/...
wss://...rhcloud.com:8443/socket.io/...

https://help.openshift.com/hc/en-us/articles/203263674-What-external-ports-are-available-on-OpenShift

Upvotes: 1

Related Questions