Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find a rare bug?

My application contains a bug, which makes script run infinitelly long. When I force script to stop, all jQuery UI elements don't answer to my actions, nor application answers to keypresses.

If I choose to open Firebug, it requires reloading page and all current application state is lost.

The thing is I can't reproduce this bug and it's kinda driving me crazy. How to find and fix such slick bug?

UPDATE. Thanks all of you for the advice. But the problem is that I can't figure out when bug happens and, hence, can't reproduce it. That's why standard procedures won't work in my case.

I have examined every while loop and recursive function calls, but haven't figured out the problem yet.

Publishing the code isn't a good idea — code listing is huge and rather complicated (a game).

POSSIBLE SOLUTION. I'll follow one of the published hints and will try to consolelog all functions that might be causing the problem. Hope it helps.

like image 929
Denis Kulagin Avatar asked Mar 11 '12 10:03

Denis Kulagin


2 Answers

There are two main approaches for dealing with this:

  1. Set break points and step through your code
  2. Start commenting out certain sections of code. Once you comment out a section that eliminates the bug, start commenting out smaller pieces of that section until you arrive at the line of code that is causing the issue.

It might also help to know what you are looking for. An infinitely running script will generally result from one of two things:

  1. A loop that never terminates.
  2. A function that calls itself

Keeping an eye out for these things might help the debugging process go a bit more quickly. Good luck!

like image 149
maxedison Avatar answered Sep 30 '22 16:09

maxedison


  • break your code into chunks and determine which one causes failure. like for example, if you have a form with several fields that have date-pickers and auto-completes, take them apart one by one. zero-in on who causes it.

  • use the debugger timeline. cruise around your site with the timeline recording your page performance. you will see in the timeline which task it taking too long. the browser may crash when you find the bug, but you will at least see a glimpse of what happened when.

  • try to recreate your actions. do some step-by-step checklist on how you navigate through. this way, you can trace in the code the possible path your script took when you did your move. if only JS had a back-trace like PHP, this would be easier.

  • try to review your code. things like loops, recursions or even two functions calling each other can cause this never-ending loop.

  • if you could, use a VCS tool like SVN or GIT. you can easily build n' break your code without the worry of losing a working version. you can revert easily if you use VCS.

like image 35
Joseph Avatar answered Sep 30 '22 16:09

Joseph