ChallengeThe invisible concurrency bug–Answer
The bug from yesterday would only show when a particular query is being run concurrently, and not always then.
Here is the code that is responsible for the bug:
It is quite hard to see, because it is so subtle. The code here create a cached lambda that is global for the process. The lambda takes the current engine, the object to transform return the converted object.
So far, so good, right?
Except that in this case, the lambda is capturing the engine parameter that is passed to the function. The engine is single threaded, and must not be used concurrently. The problem is that the code already handles this situation, and the current engine instance is passed to the lamda, where it is never used. The original engine instance is being used concurrently, violating its invariants and causing errors down the line.
The fix was to simply use the current engine instance that was passed to us, but this was really hard to figure out.