Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a 500 Internal Server Error response be cached by a browser?

While debugging a production issue, we found that GET requests to a URL is returning a 500 Internal Server Error for one user but returning 200 OK for everyone else. It had appeared that the 500 was being served from the cache, but any attempt since to reproduce this bug was unsuccessful.

My question is: is it possible for an error response to be cached by the browser? If so, which browsers support it and what cache headers would I need to replicate it?

My intuition is that the error response shouldn't be cached because you will continue to be denied service even though the bug has been fixed. Based on Which HTTP status codes are cacheable? it also seems like 500 shouldn't be cacheable at all. Is caching policy implemented consistently across browsers?

like image 980
kevwang29 Avatar asked Oct 12 '16 18:10

kevwang29


People also ask

Why does my browser keep saying 500 internal server error?

Basically, the server that hosts the website you are trying to reach cannot complete your request. The issue causing the 500 error message could be a permissions or security issue with the server, the website reaching its memory limit, bad files on the site or a bad cache on your device, among other issues.

Can 500 internal server error be fixed?

Repair the database or fix the database credentials Another common problem that can cause the “500 Internal Server Error” is a corrupted database of your website. You may consider restoring the database from a backup or repairing it. For WordPress, the error may occur if the website fails to connect to the database.


1 Answers

A 500 Internal Server Error is specified to be not cacheable by default. For reference see Section 6.1 of RFC 7231 and Section 6.6.1 500 Internal Server Error of RFC 7231. If a 500 would be cacheable by default, the spec would define that explicitly.

However, depending on explicit caching headers this behavior can be overridden and it totally can happen that a 500 response is being cached because Section 3 of RFC 7234 says, amongst other relevant things to your problem, this:

Note that any of the requirements listed above can be overridden by a cache-control extension;

My guess is that something has been messed up with caching headers in case of a 500 error.

To provoke caching of a 500 response one could try to set the public flag in the Cache-Control response header.

like image 79
rmoestl Avatar answered Sep 27 '22 21:09

rmoestl