Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use Request timeout and Gateway timeout

I am writing a wrapper over a Third party API.

If I don't get response for certain time I throw the gateway timeout exception.

But i can see there is one more HttpStatus.REQUEST_TIMEOUT other than HttpStatus.GATEWAY_TIMEOUT

I don't know which one to use and when.

Any help is appreciated.

like image 801
Awadesh Avatar asked May 21 '18 12:05

Awadesh


People also ask

When should I use gateway timeout?

The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.

What is the reason for 504 Gateway Timeout?

The HyperText Transfer Protocol (HTTP) 504 Gateway Timeout server error response code indicates that the server, while acting as a gateway or proxy, did not get a response in time from the upstream server that it needed in order to complete the request.

Is a 504 Gateway Timeout my fault?

The 504 “Gateway Timeout” Error indicates that the browser sent an HTTP request to the server and it did not receive a response in time from another server to complete the request. In most cases, you can resolve it by refreshing the web page.

What happens when request timeout?

The HyperText Transfer Protocol (HTTP) 408 Request Timeout response status code means that the server would like to shut down this unused connection. It is sent on an idle connection by some servers, even without any previous request by the client.

Why should you handle response timeout while calling any API?

Request timeouts are useful for preventing a poor user experience, especially if there's an alternative that we can default to when a resource is taking too long.


1 Answers

Once your server is acting as a gateway or proxy of an upstream server, you should use 504 to indicate that the connection has timed out. See how this status code is defined:

6.6.5. 504 Gateway Timeout

The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.

The 408 status code has a completed different meaning and indicates that the server would like to shut down an unused connection with the client:

6.5.7. 408 Request Timeout

The 408 (Request Timeout) status code indicates that the server did not receive a complete request message within the time that it was prepared to wait. A server SHOULD send the "close" connection option in the response, since 408 implies that the server has decided to close the connection rather than continue waiting. If the client has an outstanding request in transit, the client MAY repeat that request on a new connection.

like image 99
cassiomolin Avatar answered Oct 02 '22 15:10

cassiomolin