I just realised that we download the Maxmind databases in a background thread while running assets:precompile at the same time. Based on the backtraces I am seeing, I have a hypothesis that the background thread which we use to download the Maxmind database is messing with assets:precompile somehow.
https://github.com/discourse/discourse/pull/28157
I’m going to ship the fix above first and not dive too deep into the root cause since we are going to be moving downloading of Maxmind databases out of the build process.