question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS EC2 Behind ELB Always Prints Error Unexpected response code: 400

See original GitHub issue

Hey guys -

Can’t seem to find out a solution for this, but when I run my app behind a load balancer, I get this error on the client:

WebSocket connection to 'wss://fakedomain.com/socket.io/?EIO=3&transport=websocket&sid=QH8VmXbiEcp3ZyiLAAAD' failed: Error during WebSocket handshake: Unexpected response code: 400 

I understand the error, since it’s trying to talk to the load balancer and now the EC2 instance (I’m not great with AWS so feel free to offer help on this one!) but what I don’t understand is how to make the error not show up!

I’d love to fix the root cause but I’m guessing it involves a separate dedicated socket.io server to handle all the real time stuff which I don’t have time for at the moment, but could someone please run me through supressing this error?

I’m assuming it’s falling back to polling, which seems to work just fine (I have the socket connection connected and it fires) but I don’t want to launch with a red error in my console.

Thanks in advance for any advice you might have!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:67

github_iconTop GitHub Comments

62reactions
yadscommented, Oct 30, 2014

I assume you’re not using Elastic Beanstalk (the instructions there would be much easier).

Go to EC2->Network & Security->Load Balancers

Select your load balancer and go to Listeners. Ensure that both the Load Balancer protocol and the Instance Protocol are set to TCP for port 80 and SSL for port 443 rather than HTTP and HTTPS.

25reactions
williamcoatescommented, Mar 8, 2016

I found that on Elastic Beanstalk even though i had setup the Load balancer to use TCP and SSL with the web interface, when I checked the load balancer config directly it was still using HTTPS for the secure listener. So you should probably check in the EC2 > Load Balancers section that the ports are setup as they should be:

screen shot 2016-03-08 at 16 08 34

Once that is sorted add the following to .ebextensions and all works well for me 😃

container_commands:
  01_nginx_static:
    command: |
      sed -i '/\s*proxy_set_header\s*Connection/c \
              proxy_set_header Upgrade $http_upgrade;\
              proxy_set_header Connection "upgrade";\
          ' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf

This will only work 100% when you only have one instance however, because sticky session support doesnt work over TCP.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot your Application Load Balancers
The target response code was malformed or there was an error connecting to the target. Verify that your application responds to the load...
Read more >
AWS EC2 Behind ELB Always Prints Error Unexpected response ...
AWS EC2 Behind ELB Always Prints Error Unexpected response code : 400. ... but when I run my app behind a load balancer,...
Read more >
400 Bad Request On Socket Connection Hosted On Amazon ...
400 Bad Request On Socket Connection Hosted On Amazon Application Load Balancer ... EC2 Behind ELB Always Prints Error Unexpected response code: 400....
Read more >
AWS Solutions Architecture Associate Practice Questions Part 6
Each tier consist of Amazon EC2 instances behind an ELB Classic Load Balancer. The instances run in Auto Scaling groups across multiple ...
Read more >
ASP.NET Core SignalR connection troubleshooting
This error is usually caused by a client using only the WebSockets transport but the WebSocket protocol isn't enabled on the server. Response ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found