6

I'm trying to get a .NET Core application running on elastic beanstalk to receive websockets connections from javascript in the browser.

When I test my client and server outside AWS on my local machine I am able to establish a websocket connection betwen the two. But when I deploy the server to elastic beanstalk I get the following error

WebSocket connection to 'ws://52.62.253.144/' failed: Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing

The server replies with a 101 Switching Protocols, so I know the server is trying to establish the connection, but the Sec-WebSocket-Accept header is missing. When testing locally, this header is present.

Is it possible elastic beanstalk is stripping the Sec-WebSocket-Accept from the response? It is currently configured in a 'Single Instance' scenario, not autoscaling.

Thanks in advance

ChrisBellew
  • 994
  • 10
  • 25

3 Answers3

2

Same thing happened to me in a Tomcat/Java project, it was finally fixed by switching the ELB protocols to TCP/SSL. The official documentation shows you how to switch them, can you try this and let me know.

imTachu
  • 3,491
  • 4
  • 24
  • 52
  • +1. We also have an application that uses web-sockets deployed with ElasticBeanstalk and we switch `ListenerProtocol` to TCP/SSL to get it work. – endertunc Oct 28 '16 at 13:23
  • I'm trying the application load balancer now, which is what AWS suggests I use for websockets, but I'm still getting the same error. I've tried enabling session stickiness. I also get the same error when i bypass the load balancer and hit the IP directly. The EB is in single instance mode. Nothing I do seems to work :( – ChrisBellew Nov 17 '16 at 09:57
  • Fixed it! I had to install Websockets on IIS 8 by going to Server Manager > Manage > Add Roles and Features > Web Server > Application Development > Websockets. Hope this helps someone else! – ChrisBellew Nov 19 '16 at 01:51
0

AWS do not accept unserscores(_) in headders, while we can use (-), So Remove underscores from the header variables, example:- header_var_val = "some value" replace it with headervarval = "some value". It works for me.

Rishabh Jhalani
  • 739
  • 6
  • 17
0

It might not work for everyone but I had the same issue and I realized that a large amount of cookies were forwarded because I used the same domain for website and websocket.

When I flushed the cookies the Sec-WebSocket-Accept header came back.

It would be interesting to know if it is because of the header length or because of a bad character in the cookies.

EDIT

It seems that the length is the issue. The best practice is to use separate domains for websocket and site because according to the following question it is not possible to disable cookies in the header while creating a websocket.

How to disable cookies in Header while creating websocket?

RafaSashi
  • 14,170
  • 8
  • 71
  • 85