I have a Worker which caches a page in Cloudflare if certain conditions are met, otherwise it bypasses the cache and fetches from the origin.
It works well, but sometimes a Cloudflare POP will simply return a blank cached page. Accessing the page via other POPs works as expected. A user has reported an affected URL now from the Seattle POP which has allowed me to experiment further with this bug.
I checked my origin server’s Nginx logs and found it served all requests to the URL with a successful
200 response and the expected
$body_bytes_sent. This confirms the problem occurred in Cloudflare’s Seattle POP.
Has anyone else experienced something like this, or does anyone have recommendations for mitigation? It seems Cloudflare’s cache cannot be trusted and I will have to come up with some checks on my own for this condition if I want to keep using it.
I am already checking for a successful
200 HTTP response code before storing pages into the cache, but that clearly isn’t the issue. My only other idea is to actually check the response body returned from the cache is not empty before sending it back to the user, but I am concerned that might introduce a small delay and increase the Worker’s TTFB.
This problem is particularly insidious in that I have no way of knowing when a given POP somewhere around the world is returning a blank white page for a URL (unless a user reports it) and there are no error messages or error status codes logged anywhere. If it happens in a major POP I could lose a lot of traffic to my site.