Limit for concurrent connections to web service that triggers 502 Bad Gateway

We have a web service in Node.js that collects data from IoT devices and exposes an API endpoints which return monthly reports for this data in a JSON format.

Because our database queries are not yet optimized (we are still on 0.1 CPU plan) API responses became slow at the and of month, reaching even over 10 seconds.

At that point our web service started to respond with 502 Bad Gateway status code (content-type: text/html) for most requests.

This included Health check endpoint which caused Server unhealthy state and service restarts (which didn’t help).

My theory is that when web service reaches certain number of concurrent connections, Render starts to respond with above 502 Bad Gateway response.

I can understand why it’s happening, however this behavior is not documented at all and so I had hard time figuring it out.

Is there a limit for concurrent connections to web service that triggers 502 Bad Gateway?

By the way, I set server.keepAliveTimeout and server.headersTimeout to 120s as suggested in docs, but that didn’t help at all.