How do you reproduce bugs that occur sporadically?

前端 未结 28 1229
离开以前
离开以前 2021-01-30 19:43

We have a bug in our application that does not occur every time and therefore we don\'t know its \"logic\". I don\'t even get it reproduced in 100 times today.

Disclaime

28条回答
  •  孤街浪徒
    2021-01-30 20:36

    There's a good chance your application is MTWIDNTBMT (Multi Threaded When It Doesn't Need To Be Multi Threaded), or maybe just multi-threaded (to be polite). A good way to reproduce sporadic errors in multi-threaded applications is to sprinkle code like this around (C#):

    Random rnd = new Random();
    System.Threading.Thread.Sleep(rnd.Next(2000));
    

    and/or this:

    for (int i = 0; i < 4000000000; i++)
    {
        // tight loop
    }
    

    to simulate threads completing their tasks at different times than usual or tying up the processor for long stretches.

    I've inherited many buggy, multi-threaded apps over the years, and code like the above examples usually makes the sporadic errors occur much more frequently.

提交回复
热议问题