502 Bad Gateway error: routing infra can't connect to instance

Hey everyone, I’ve been having an issue with Render for weeks now, where once every 4 - 6 hours, a request to my web service (running a node.js express app) would get a 502 Bad Gateway response. The error is always this:

<main class="text-primary">
  <div class="request-id">
    Request ID: 9178d715741584bb-PDX
  </div>
  <div>
    This service is currently unavailable. Please try again in a few minutes.
  </div>
  <div>
    If you are the site owner, refer to 
    <a href="https://render.com/docs/troubleshooting-deploys#502-bad-gateway">
      Render's documentation
    </a>
    for troubleshooting.
  </div>
</main>
  1. After speaking with support, they mentioned the routing infra was unable to connect to my instance.

  2. The problem is very transient. Requests before and after are all successful

  3. It’s not reaching my express app as I have a middleware set up directly at the entry point to log the request, and I’ve not seen it come through.

I was told to set up a retry mechanism, but I’m not sure how to do that since I’m not even able to handle the request.

Anyone faced this problem before or have advice on how to deal with it?