I had this on an ESP32 once. Turned out spitting out serial console debug messages slowed things down enough to resolve a race condition when I tried to see what was happening. I learned more about using an actual debugger after that instead of spitting out “here” messages and variable values.
The technical term is Heisenbug: https://en.wikipedia.org/wiki/Heisenbug
I had this on an ESP32 once. Turned out spitting out serial console debug messages slowed things down enough to resolve a race condition when I tried to see what was happening. I learned more about using an actual debugger after that instead of spitting out “here” messages and variable values.