简体   繁体   中英

org.springframework.web.client.RestTemplate 504 Gateway Timeout

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.

The HTTP Proxy properties are not set in your Java environment.

Look at the following: https://docs.oracle.com/javase/8/docs/api/java/net/doc-files/net-properties.html

In the section Proxies , it explains the following

  • http.proxyHost (default: ) The hostname, or address, of the proxy server

  • http.proxyPort (default: 80) The port number of the proxy server.

  • http.nonProxyHosts: Indicates the hosts that shouldn't go through the proxy.

  • https.proxyHost, https.proxyPort: Same as above, but for https and uses http.nonProxyHosts for whitelist.

On my own cases, I had the wrong format for http.nonProxyHosts and it can be used for both HTTP and HTTPS variables. The delimiter for multiple hosts is a pipe | and NOT a comma , .

For instance:

-d http.nonProxyHosts="*.mycompany.com|*.mycompany.net"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM