Inconsistent Signed-In State behind fastly

AI-generated summary

Inconsistent Signed-In State behind Fastly

JackCA is experiencing an issue where, after logging in, the UI appears as if they’re not signed in when navigating directly to their forum’s home page. However, navigating to a specific post and then using pushstate transitions resolves the issue, until a reload is performed.

JackCA suspects the problem may be related to Fastly’s caching layer and the no-cache, no-store Cache-Control response header. Fastly does not respect these values, and instead, caches the page. As a temporary solution, JackCA has implemented adding an Expires: 0 header, as suggested by Fastly’s documentation.

I’m having a bit of a strange issue but there are a lot of factors at play.

Issue:

when I am logged in and I navigate directly to my forum’s home page, it appears as if I’m not logged in, in the UI e.g. the navbar has sign-up/sign-in links instead of the user avatar.

Navigating directly to a specific post, will result in the correct signed-in state and subsequent pushstate transitions work, including going to the home page. However, a reload on the homepage will result in it appearing logged out (as above).

Background:

I am using discourse fully behind Fastly, except for the polling functionality which is communicating directly with my GCP Compute Instance.

My guess is that this has something to do with the caching layer, but I have been pretty careful to read through the discussions on this forum. I do not have Fastly’s automatic GZIP compression turned on.

The forum is here and here’s a video of the above.

Upon further investigation, I think the issue may be related to when the Cache-Control response header is no-cache, no-store in combination with Fastly not respecting those values.

My Fastly CDN was marking what looked like a noscript version of the home page for a web crawler as HIT’s because it must have crawled with the no-cache, no-store value.

Fastly suggests adding an Expires: 0 in situations like this.

I’ve implemented this as suggested by the fastly docs in the meantime.