RubbaBoy / BYOB

Bring Your Own Badge - Create dynamic README badges based off of your GitHub Actions
MIT License
80 stars 10 forks source link

Caching is sometimes failing #9

Closed Mulugruntz closed 1 year ago

Mulugruntz commented 2 years ago

As mentioned in #8 , there seems to be some issues related to caching. I'm guessing this is caching, because when going directly to the link and refreshing the page, it seems to "sometimes" resolves the issue.

But maybe it's different.

An example here: image

Mulugruntz commented 2 years ago

This is what I see when accessing https://github.com/RubbaBoy/BYOB/issues/8 and inspecting the unreachable badge.

We can see that the neat https://byob.yarr.is/mulugruntz/celery-pubsub/m_linux_3.8_celery345 link got replaced by https://camo.githubusercontent.com/43939e1e54e7f73a96439b7b826f0b7ef1c624e61b17160107bb5a9d464be9b0/68747470733a2f2f62796f622e796172722e69732f6d756c756772756e747a2f63656c6572792d7075627375622f6d5f6c696e75785f332e385f63656c657279333435 probably through GitHub's caching policy.

Also, there's x-cache: MISS and x-cache-hits: 0.

General ``` Request URL: https://camo.githubusercontent.com/43939e1e54e7f73a96439b7b826f0b7ef1c624e61b17160107bb5a9d464be9b0/68747470733a2f2f62796f622e796172722e69732f6d756c756772756e747a2f63656c6572792d7075627375622f6d5f6c696e75785f332e385f63656c657279333435 Request Method: GET Status Code: 404 Remote Address: 185.199.108.133:443 Referrer Policy: no-referrer-when-downgrade ``` Response Headers ``` accept-ranges: bytes cache-control: no-cache, no-store, private, must-revalidate content-length: 10 content-security-policy: default-src 'none'; img-src data:; style-src 'unsafe-inline' content-type: text/plain; charset=utf-8 date: Wed, 24 Nov 2021 09:23:29 GMT server: github-camo (fa497f37) strict-transport-security: max-age=31536000; includeSubDomains timing-allow-origin: https://github.com via: 1.1 varnish x-cache: MISS x-cache-hits: 0 x-content-type-options: nosniff x-fastly-request-id: 220f1d3200c60fa36b8d5bfbb5099392d71f5c5e x-frame-options: deny x-github-request-id: 0AC4:02F6:3AB08:6BB63:619E0491 x-served-by: cache-itm18829-ITM x-timer: S1637745810.718696,VS0,VE229 x-xss-protection: 1; mode=block ``` Request Headers ``` :authority: camo.githubusercontent.com :method: GET :path: /43939e1e54e7f73a96439b7b826f0b7ef1c624e61b17160107bb5a9d464be9b0/68747470733a2f2f62796f622e796172722e69732f6d756c756772756e747a2f63656c6572792d7075627375622f6d5f6c696e75785f332e385f63656c657279333435 :scheme: https accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8 accept-encoding: gzip, deflate, br accept-language: en-GB,en;q=0.9,en-US;q=0.8,fr;q=0.7,ja;q=0.6 referer: https://github.com/RubbaBoy/BYOB/issues/8 sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96" sec-ch-ua-mobile: ?0 sec-ch-ua-platform: "macOS" sec-fetch-dest: image sec-fetch-mode: no-cors sec-fetch-site: cross-site user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 ```

As a comparison, this is the result of the one that works, with x-cache: HIT and x-cache-hits: 1:

General ``` Request URL: https://camo.githubusercontent.com/c2644fe3aceba579ea1a445105eb931f56893be14189227baa801a7e27fe31b9/68747470733a2f2f62796f622e796172722e69732f6d756c756772756e747a2f63656c6572792d7075627375622f6d5f6c696e75785f332e385f63656c65727933 Request Method: GET Status Code: 200 Remote Address: 185.199.108.133:443 Referrer Policy: no-referrer-when-downgrade ``` Response Headers ``` accept-ranges: bytes age: 10 cache-control: no-cache content-length: 8459 content-security-policy: default-src 'none'; img-src data:; style-src 'unsafe-inline' content-type: image/svg+xml date: Wed, 24 Nov 2021 09:23:29 GMT server: github-camo (fa497f37) strict-transport-security: max-age=31536000; includeSubDomains timing-allow-origin: https://github.com via: 1.1 varnish x-cache: HIT x-cache-hits: 1 x-content-type-options: nosniff x-fastly-request-id: 24a18705b3cd64971a5c1b37592c91997dc818c5 x-frame-options: deny x-github-request-id: CD08:02F7:B993D:EAB39:619E0487 x-served-by: cache-itm18829-ITM x-timer: S1637745810.719076,VS0,VE0 x-xss-protection: 1; mode=block ``` Request Headers ``` :authority: camo.githubusercontent.com :method: GET :path: /c2644fe3aceba579ea1a445105eb931f56893be14189227baa801a7e27fe31b9/68747470733a2f2f62796f622e796172722e69732f6d756c756772756e747a2f63656c6572792d7075627375622f6d5f6c696e75785f332e385f63656c65727933 :scheme: https accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8 accept-encoding: gzip, deflate, br accept-language: en-GB,en;q=0.9,en-US;q=0.8,fr;q=0.7,ja;q=0.6 referer: https://github.com/RubbaBoy/BYOB/issues/8 sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96" sec-ch-ua-mobile: ?0 sec-ch-ua-platform: "macOS" sec-fetch-dest: image sec-fetch-mode: no-cors sec-fetch-site: cross-site user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 ```

To be noted that it also happened sometimes with valid badges.

RubbaBoy commented 2 years ago

So when a badge isn't found, a 404 is returned on the image. Camo will only display images with a 200 status code (cache is ignored otherwise, which is why the x-cache is MISS and it makes a unique request to BYOB each time). What are you expecting to see, other than an invalid image? I can't speak for valid badges having this happen to them, I've seen that bug in the past but I haven't been able to reproduce it recently, I will keep trying though (x-cache MISS will appear if the cache has expired and a new request is sent to BYOB, however, it is still displayed).

Edit: I did just find this bug occur while manually sending requests on a valid badge, it appears as if badgen gave an invalid XML response and it couldn't parse it. I will be looking more into this, however, this is a separate issue from the non-200 response images being invalid.

RubbaBoy commented 2 years ago

I am fairly convinced the issue regarding valid badges not being displayed has been fixed, today I have moved away from the hosted Badgen service and migrated to a local version, so reliability is much higher now that it is completely self-contained.