Could never reproduce it but tried to make this codepath more resilient, let me know if it works. If it doesn’t please try to come up with a clear repro if possible.
https://github.com/discourse/discourse/commit/d54da517d9c58862a576174d1ae5b0c4d67641cb