Websockets connection failure on amazon ec2

user371427 picture user371427 · Aug 6, 2012 · Viewed 16.7k times · Source

I have a netty server running the atmosphere framework for a real-time notification system over websockets.

The system works perfectly on my local machine, but when I deploy it on EC2, It just does not seem to work. I am able to telnet to the remote Netty server though. The server is accessible and ports are open on EC2

Firefox throws the following error

Using URL: ws://beta.myapp.com:2880/myhandle?id=1&name=Chinese_food_rule_2&    X-Atmosphere-tracking-id=35490c47-59d6-abf6-36fa-431aa340d90a&X-Atmosphere-Framework=0.9&X-Atmosphere-Transport=websocket&X-Cache-Date=0&Content-Type=application/json

Websocket error, reason: undefined

Firefox can't establish a connection to the server at ws://beta.myapp.com:2880/myhandle?id=1&name=Chinese_food_rule_2&X-Atmosphere-tracking-id=35490c47-59d6-abf6-36fa-431aa340d90a&X-Atmosphere-Framework=0.9&X-Atmosphere-Transport=websocket&X-Cache-Date=0&Content-Type=application/json.

Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent).

The server does not even get a request, this leads me to think that this is some EC2 web sockets gotcha which I am not aware of.

Answer

moodh picture moodh · Oct 15, 2012

Are you using an ELB? If yes you'll need to switch over to TPC instead of HTTP as websockets isn't supported in the HTTP layer. You will lose stickiness and the possibility to retrieve client IP when running TCP but Websockets will work all the way through. =)

More information on EC2/ELB/Websockets:
http://johan.firebase.co/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions-in
http://johan.heapsource.com/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions-in https://web.archive.org/web/20160328183724/http://johan.heapsource.com/post/31047804966/the-state-of-websockets-ssl-and-sticky-sessions