I am making a http request using org.springframework.web.client.RestTemplate with no updates to the connection timeouts of it, which I believe would make it an infinite request. However every once in a while this 504 gateway timeout occurs. Could this be caused by the server we are requesting too, maybe it is taking to long on their end and they cut it off? Is that a possibility or is this more on my end?
It's not your fault. A backend server could not communicate with an upstream server on time. This can happen for example if Nginx (a proxy that could be acting as a gateway to the requests) is communicating with a couple of glassfish server instances and one of them goes down. It cannot receive a response from a server that is down and the communication will timeout at which point it will return a HTTP 504
.
I've faced similar problems with REST services that I've exposed. It takes a few seconds to determine Qos on a misbehaving service and bring it out of traffic. At this point in time, while the faulty server is still serving traffic, a gateway may decide to send a 504
. The server will eventually be removed from traffic and things go back to normal.