Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tips for debugging hard-to-reproduce concurrency bugs?

What are some tips for debugging hard to reproduce concurrency bugs that only happen, say, once every thousand runs of a test? I have one of these and I have no idea how to go about debugging it. I can't put print statements or debugger watches all over the place to observe internal state, because that would change timings and produce overwhelming amounts of information when the bug is not successfully reproduced.

like image 480
dsimcha Avatar asked Feb 02 '23 18:02

dsimcha


2 Answers

Here is my technique : I generally use a lot of assert() to check the data consistency/validity as often as possible. When one assert fails, the program crashes generating a core file. Then I use a debugger with the core file to understand what thread configuration led to data corruption.

like image 104
Ben Avatar answered Feb 05 '23 15:02

Ben


This might not help you but will probably help someone seeing this question in the future.

If you're using a .Net language you can use the CHESS project from Microsoft research. It runs unit tests with every kind of thread interleaving and shows you which ones cause the bug to happen.

There may be a similar tool for the language you're using.

like image 26
Bryan Anderson Avatar answered Feb 05 '23 17:02

Bryan Anderson