New user around here so still learning my way around.
I have a pretty vanilla Rails app where I’m experiencing an odd behaviour: if I request my page a dozen times, 3 or 4 times the server will respond back with an old version of the app.
I can see this by looking at the HTML (and seeing an old version of it that has since been changed and deployed) and also by noting that the CSS file being requested for instance has the wrong fingerprint (and therefore fails).
fly status
App
Name = <name>
Owner = personal
Version = 8
Status = deployed
Hostname = <hostname>
Platform = detached
Instances
ID PROCESS VERSION REGION DESIRED STATUS HEALTH CHECKS RESTARTS CREATED
a0ac9992 app 8 mad run running 1 total, 1 passing 0 9h7m ago
Initially I suspected some browser caching but have since discarded that (by disabling cache and trying different browsers), the “old” code is definitely coming from the server.
I’ve also tried looking through the dashboard and find cache items but no luck so far.
Am I missing something quite obvious? Has anyone seen something similar?
I can see the [[statics]] section there so maybe this is a caching problem?
Do you use any sort of cache invalidation method on rails such as having a digest inside the CSS URL on your HTML or are your stylesheets always under the same URL? Do you happen to know if the wrong styles come from certain fly regions? (You can verify response headers on your browser devtools).
I can see the [[statics]] section there so maybe this is a caching problem?
Good point. But to be fair I’m not sure what that section does.
Do you use any sort of cache invalidation method on rails such as having a digest inside the CSS URL on your HTML or are your stylesheets always under the same URL? Do you happen to know if the wrong styles come from certain fly regions? (You can verify response headers on your browser devtools).
A bit more detail on my near-vanilla setup. The only thing I added is tailwindcss-rails.
Ruby 3.0.2, Rails 7.0.5.
The tailwind CSS file is compiled on precompile and is fingerprinted. Whenever I change the file’s contents it changes the fingerprint.
This being said, I think this is definitely something related to my fly setup or a problem on fly’s side.
Here’s the link of a fingerprinted CSS file on my application:
If you request this file multiple times you see that it fails with a 404 sometimes and it succeeds with 200 in others. I checked my app (fly ssh console) and the file is definitely in the public/assets folder.
How can it be served sometimes and fail in others?
I think this could be a problem on our side, your app seems to have an allocation (Fly v1) and a machine (Fly v2) running, I can see your app is on Platform = detached so that’s why I’m hinting at that. Can you experiment with running these commands?
# Remove nomad VMs. This won't affect your machines.
fly scale count 0
# That ^ takes a few minutes to process on the backend after you've run it.
fly apps set-platform-version machines # you should be good after this!
At some point, your app was migrated from v1 to v2 (either on your end or automatically) but must have failed to finish it and stop the nomad VM (Fly v1) so our proxy understood that your app had two VMs running, one of them containing an old version of your app.
Fortunately, no migrations will be happening further on your app since you changed your platform version to machines already