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.

Question: What could be the possible reasons for socket-io server returning 400 Bad Request via nginx?

See original GitHub issue

Hi,

We are facing a scenario where a good percentage of requests going to /Socket.io/?... is returning with 400.

Default nginx access log results are littered with:

10.0.0.82 - - [04/Dec/2015:11:43:27 +0000] "GET /socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=websocket HTTP/1.1" 400 45 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"

The requests are not even reaching our overlying SailsJS server. We suspect something going wrong at socket-io layer. Any thought?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:29 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
shamasiscommented, Dec 5, 2015

After a LOT of painstaking log-watching, this is our temporary solution for nginx config (to stop freaking out our servers.) The following directive checks for missing “Upgrade” header in request and returns with a 202 without hitting the node server.

location /socket.io {
    set $local_upgrade_failure "${arg___sails_io_sdk_platform}${arg_transport}${connection_upgrade}";
    if ( $local_upgrade_failure = "browserwebsocket" ) { return 202; break; }

 ... remain proxy configurations
}

Now, this does NOT fix the clients that are sending these requests, but surely frees up the server. Now, the question is @rauchg, why are some socket.io clients not sending the “upgrade” header? One pattern is that they are all Windows and a very few Linux machines. Did not spot a single OSX in one full hour of heavy usage.

2reactions
shamasiscommented, Jun 12, 2016

I will then have to deep dive into socket.io - it’s being returned by socket.io with no additional message -

{ code: 3, message: “badRequest”}

Read more comments on GitHub >

github_iconTop Results From Across the Web

nginx as webserver incl. socket.io and node.js / ws:// 400 Bad ...
The problem is that ws:// doesnt work. If the system using xhr polling i could use ajax requests to background server instead using...
Read more >
Socket.io call throwing 400 Bad Request for some users
I'll urge to you check your Nginx Error Logs, the error will most certainly be logged there. Once it's logged there it will...
Read more >
"Bad Request" when sending request to Socket.IO app via ...
The answer turned out to be very prosaic. As it turned out, the front-end had version 2 of Socket.IO , and on the...
Read more >
Troubleshooting connection issues | Socket.IO
Possible explanations : a proxy in front of your servers does not accept the WebSocket connection.
Read more >
400 Bad Request - SSL Certificate Error | Apigee Edge
During the TLS handshake if it is found that the client certificate is expired, then the server will send 400 - Bad request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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