Well this was fun to debug. I changed this recently from a ton of API calls to direct DB queries as part of a massive HTTP overhaul we're doing internally (moving internal traffic to HTTPS).
In the method, it's now a
Parallel.ForEach fetching many site moderators at once (we need data stored in each site's database). 3 methods down there was a "current context" access, which looks at, ultimately, the current request. This doesn't work in a background thread.
"Hey Nick, why don't you test your damn code?" Well I did, but locally and in dev (not visible to the public), there is at most 1 site in the loop. In .NET, a shortcut happens on
Parallel.ForEach where it doesn't need to allocate all the sharding and parallelism bits...so it just runs on the current thread. Because of that, the "current context" access was fine. When it got to production with hundreds of sites: boom.
So, sorry about that. A fix has just finished deploying and all should be well.