A classic Heisenbug moment!
If it works fine watching it and breaks the moment you stop watching, that is a known Heisenbug.
How do you go about chasing or reproducing it?
Do you throw in any number of trace events or fiddle with timings or any fanciful fix that sounds good on paper?
Yes, quite a few times and also the opposite where bug only appears in debug mode, its a common it works on my machine check, do you have debugger running.
I suspect with AI you explain this scenario and give it the context of the most likely code and it could analyze the code from this aspect.
Or do that research yourself, you will often find these things on reddit with potential solutions.
It’s almost always threading related when that happens. Traces and even console print statements invariably interlock ever so briefly to prevent the state of whatever you print/log to form being toast, and that tiny interlock allows threads enough time to catch up or overtake each other. t’s less about slowness and more about assumptions around order of execution when enabling or adding trace causes bugs to go away. This is commonly seen around object construction or destruction too, which makes it harder to reason about and harder to debug.
So yeah, normally I start with code reviews, then I look at speeding up the tracing framework.
That’s a great explanation — the timing shift from trace interlocks is such a sneaky culprit! I’ve seen similar cases where even minimal log overhead completely masks race conditions.