HTTP 502 Server Hangup. What are the causes? - node.js

We are querying a node.js based server in our company and of the servers every so often throws a http status 502 after exactly 2 minutes saying "Server Hangup". I saw a lot of questions being asked on stackoverflow but I couldn't find a definitive answer. The way to reproduce this issue is doing an HTTP POST request to the server. The GET requests are fine.
I try the exact same requests to other similar servers and I've never got a 502. I have read everything about what 502 means but I am not sure what could be wrong with the server? Maybe a tcpdump on that server can be helpful? Could it be the server has too many connections and its not freeing them up? I would like to get some context before I email the other team with the problem.
Any feedback is appreciated.
Thanks,
KA

Related

NestJS on EC2 keeps responding with 502 randomly

I made a server with NestJS and ran it on an EC2 instance, and it is responding with 502 randomly.
I googled and a lot of articles mentioned the difference between the timeout interval of ALB and the server.
when I made a simple webpage server with express the same issue happened but fixed it by adjusting keepAliveTimeout and headersTimeout.
(each value was 65000ms and 67000ms)
however, this nestjs server still responds with 502 and I don't know what else to do.
tried to change the timeout of ALB to 30sec and to 120sec and this didn't work either.
what else is the possibility of this issue? I am lost.

IBM Domino 502 Bad Gateway on redirect

In our application we have a REST integration with another service
It worked fine untill recently, however, sometimes we are returned with 502 Bad Gateway in the application
We send HTTP requests through curl and it seems that to be working but then we are presented with the error I described above
The client is believed to have a firewall installed
Whenever we face the problem, I usually ask the administrator to turn this thing off and it does the trick but I'm not sure whether it has something to do with the code?
My question is what causes such behaviour and how to avoid it in the future?

net::ERR_SPDY_PROTOCOL_ERROR 200 with proxy server

In our project we're using 2 servers: 1 as a PROD API server and 1 as a proxy(actually nginx is used for that)
The proxy server uses HTTP/2 as well. In one scenario the proxy may get response from prod API server and replace PROD links by Proxy's and then return that to the client.
In that case we can catch the "net::ERR_SPDY_PROTOCOL_ERROR 200" error. I googled little bit about that issue, but it looks like it may be few reasons for that error.
In my case it occurs only when we replace hosts(modify the response from the PROD before sending it to client)
Can someone describe what actually the "net::ERR_SPDY_PROTOCOL_ERROR 200" means and maybe best practices to avoid that?
HTTP/2 is derived from the earlier SPDY protocol, that's probably why the error message doesn't mention HTTP/2 at all.
One of the reasons why you may see the ERR_SPDY_PROTOCOL_ERROR message is an invalid HTTP header coming from the server. Perhaps your proxy is making some change to an HTTP response header which is making it invalid/malformed?
Try to disable HTTP/2 on your proxy server and see if the error goes away. If it does, inspect the response headers and make sure they are valid. I suspect your proxy server is malforming the response.
We met similar issue today when running the reverse proxy server using docker image: nginx:1.16.0-alpine. After changing to use nginx:1.16.0, this issue was solved.

express server on node.js returning 501 for patch calls

I'm at a loss with a problem that been bugging me for a few days. My express server is returning me 501s for all patch calls. (I believe they used to work).
Does anyone have any suggestions or a way that I could debug express to find where my problem is coming from?
Here's some info:
My route call
app.patch('/creator/sentences/:masterId/', require('./views/creator/sentences/index').updateMaster);
What I get on the client:
Request URL:http://my-url.c9users.io/creator/sentences/197/
Request Method:PATCH
Status Code:501 Not implemented
Any help would be appreciated or anyone someone thinks I could find a way to debug this.
I ended finding out that for some reason my ISP was blocking patch calls. Any other network and things were fine... Went on VPN and things were fine... So weird and now I understand why some web sites weren't working properly for me.
Patch calls must just be quite rare if the isp has this problem they don't fix.
EDIT AND SOLUTION: I ended up using https instead of http and then my isp couldn't block the patch requests :)

Cloudflare HTTP POST 524 Timeout with node.js + express

I am having a trouble using HTTP POST when cloudflare is enabled.
It keeps returning 524 timeout.
Failed to load resource: the server responded with a status of 524 (Origin Time-out)
But when I disabled cloudflare, the HTTP POST works fine.
Any idea what might caused this?
UPDATE
I am using AJAX POST, does this got anything to do with ajax?
Thanks.
General causes for a CloudFlare 524 error.
Support should be able to provide more detailed troubleshooting.
Console utility "netstat" shows that some connections from CloudFlare are in CLOSE_WAIT state. Pointing that server just sits without correctly closing connections. Looking to the TCP traffic of my web server with Message Analyzer, I found several connections that was established and http request was sent but that wasn't ever processed by my server.
So we get an answer: the number of simultaneously established connections outnumbered available Accept() calls. So TCP stack connects and wait while application will handle it's connection. Depending on the situation this can never happen, so the client side just drops this connection after a 30 sec timeout without getting any response.
To fix this, you must increase the number of outstanding possible accepts. This parameter can be named as "Max simultaneous connections number" or something similar. Check your web server documentation \ ask the support to find it out.
Also, as an experiment, you can force your server to reply with the "Connection:close" header to each request. This may prevent reaching the active connections limit problem because CloudFlare keep-alive them just way too long.
Also, the more simultaneous requests you do, the more probability to get in troubles. You can try to set some small webserver-side timeout for idle connections.
P.S.: Illustration of CloudFlare's connections number after one client loaded a page:
(http://i.imgur.com/IgwGLCf.png)

Resources