User-specific 502 errors after login — traced to DiscourseUpdates.has_unseen_features?

We encountered the same issue and traced it further down.

The root cause is DiscourseUpdates.has_unseen_features? calling GitUtils.has_commit?, which runs:

git merge-base --is-ancestor <sha> HEAD

In newer Discourse Docker images, the repo inside the container is configured as a partial clone with promisor remote. When the feature SHA is not present locally, Git attempts a lazy fetch from the remote (upload-pack), which takes ~3–4 seconds per call.

Since multiple features are checked, this results in 30+ seconds request time and eventually a 502 (Unicorn timeout), especially for staff users where this check runs.

Key points:

  • Happens only for staff (via CurrentUserSerializer)

  • Caused by missing commits in partial clone

  • Git operations on missing objects trigger slow remote lookups

  • Reproducible via git merge-base --is-ancestor <missing_sha> HEAD inside container

A simple mitigation is caching GitUtils.has_commit? results (e.g. per HEAD+SHA), which avoids repeated expensive git calls.