Contents
  1. 1. Web Servers
    1. 1.1. Nginx
  2. 2. Java HTTP Client
    1. 2.1. Spring RestTemplate
  3. 3. JavaScript HTTP Client
    1. 3.1. axios

Web Servers

Nginx

Error Information

Status Code: 504

Response:

1
2
3
4
5
6
7
<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>

Default Timeout

The default timeout for Nginx is 60 seconds.

Settings

Update proxy timeout to 180 seconds:

1
2
3
4
5
6
http {
proxy_connect_timeout 180s;
proxy_send_timeout 180s;
proxy_read_timeout 180s;
...
}

Java HTTP Client

Spring RestTemplate

Default Timeout

The default timeout is infinite.

By default RestTemplate uses SimpleClientHttpRequestFactory and that in turn uses HttpURLConnection.

By default the timeout for HttpURLConnection is 0 - ie infinite, unless it has been set by these properties :

1
2
-Dsun.net.client.defaultConnectTimeout=TimeoutInMiliSec 
-Dsun.net.client.defaultReadTimeout=TimeoutInMiliSec

Settings

1
2
3
4
5
6
7
8
9
@Bean
public RestTemplate restTemplate() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
// Time to establish a connection to the server from the client-side. Set to 20s.
factory.setConnectTimeout(20000);
// Time to finish reading data from the socket. Set to 300s.
factory.setReadTimeout(300000);
return new RestTemplate(factory);
}

JavaScript HTTP Client

axios

Default Timeout

The default timeout is 0 (no timeout).

Settings

1
2
3
4
5
6
7
const instance = axios.create({
baseURL: 'https://some-domain.com/api/',
// `timeout` specifies the number of milliseconds before the request times out.
// If the request takes longer than `timeout`, the request will be aborted.
timeout: 60000,
...
});
Contents
  1. 1. Web Servers
    1. 1.1. Nginx
  2. 2. Java HTTP Client
    1. 2.1. Spring RestTemplate
  3. 3. JavaScript HTTP Client
    1. 3.1. axios