'Google Cloud CDN serves stale content AFTER revalidation

I am attempting to use Google Cloud CDN with the stale-while-revalidate feature (Google Docs). However, even though I can see asynchronous revalidation requests being made to my backend server, the new content is never served by the CDN.

Here is an example of the response headers from the CDN:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Age: 5202
Cache-Control: max-age=60, public, stale-while-revalidate=86400
Content-Length: 90
Content-Type: application/json
Date: Tue, 08 Feb 2022 16:39:09 GMT
Server: Development/1.0
Via: 1.1 google

You can see that the age is 5205 seconds even though the max-age is 60 sec.

If it has been more than 60 seconds since the last revalidation request, I will see the revalidation request in my server logs, but the content served from the CDN continues to be outdated on future requests.

Here is an example of the response headers directly from my backend server:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: max-age=60, public, stale-while-revalidate=86400
Content-Length: 645
Content-Type: application/json
Date: Tue, 08 Feb 2022 18:09:39 GMT
Server: Development/1.0

And here is the Google Cloud Logging entry for the revalidation request. I believe it is showing that it received a 200 response as well:

{
  "insertId": "1sxvbdng2vrqnhl",
  "jsonPayload": {
    "parentInsertId": "1sxvbdng2vrqng7",
    "@type": "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry",
    "statusDetails": "response_sent_by_backend",
    "cacheId": "LAX-ba56a406"
  },
  "httpRequest": {
    "requestMethod": "GET",
    "requestUrl": "***masked request url***",
    "requestSize": "1888",
    "status": 200,
    "responseSize": "1259",
    "userAgent": "Cloud-CDN-Google (GFE/2.0)",
    "remoteIp": "***masked request ip***",
    "cacheLookup": true,
    "cacheFillBytes": "1259",
    "serverIp": "***masked request ip***",
    "latency": "0.082249s"
  },
  "resource": {
    "type": "http_load_balancer",
    "labels": {
      "backend_service_name": "test-be-service",
      "target_proxy_name": "test-lb-target-proxy",
      "project_id": "cdn-test-2-340220",
      "zone": "global",
      "url_map_name": "test-lb",
      "forwarding_rule_name": "test-lb-forwarding-rule"
    }
  },
  "timestamp": "2022-02-08T19:36:48.094836Z",
  "severity": "INFO",
  "logName": "projects/cdn-test-2-340220/logs/requests",
  "trace": "projects/cdn-test-2-340220/traces/f6a372e62f789d61c3654e50111ffcb9",
  "receiveTimestamp": "2022-02-08T19:36:48.360094896Z",
  "spanId": "d20eb70cb8d7dff4"
}

This behavior is the same whether I activate stale-while-revalidate via the Cache-Control response header or the Cloud CDN configuration interface.

Either I am not understanding how this is supposed to work, or this is a bug in Google Cloud CDN. Any help resolving this would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source