Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it appropriate to return HTTP 504 Gateway Timeout as a response if a database server times out?

In a REST service, is returning a 504 status code appropriate when the application times out waiting for a database query and is unable to complete the client's request?

504 Gateway Timeout

The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.


Currently we're just showing a generic 500 error, which gets displayed in a UI as a generic server error. There is some utility in showing to the user that it is a database timeout error (perhaps along with suggestions to reduce the scope of what they're asking for), because at the least they're armed with more useful information if they contact whoever is responsible for their server.


Any pointers to how other REST services handle a database timeout?

like image 862
gregmac Avatar asked Jan 19 '14 21:01

gregmac


People also ask

Is a 504 Gateway Timeout my fault?

They are no fault of the client. Your request is good, but the server can not generate the requested resource. The 504 Gateway Timeout error indicates that your web server didn't get a response on time from another server that it was accessing while trying to load the page.

How long does a 504 Gateway Timeout mean?

A 504 Gateway Timeout error indicates that the web server is waiting too long to respond from another server and “timing out.” There can be many reasons for this timeout: the other server is not functioning properly, overloaded, or down.

What is an HTTP 504 error?

An HTTP 504 status code (Gateway Timeout) indicates that when CloudFront forwarded a request to the origin (because the requested object wasn't in the edge cache), one of the following happened: The origin returned an HTTP 504 status code to CloudFront. The origin didn't respond before the request expired.


1 Answers

I would return 500 as well, with details in the payload indicating what went wrong. This is the description for 504 from RFC 2616:

The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access in attempting to complete the request.

That error description for 504 indicates that the server is acting as a gateway or proxy, which your service is definitely not doing.

like image 128
Mike Dunker Avatar answered Oct 20 '22 14:10

Mike Dunker