from Hacker News

Heisenbug

by crisp on 2/25/18, 7:29 AM with 33 comments

  • by madethemcry on 2/25/18, 10:41 AM

    One of the first heisenbugs I encountered was IE8's console.log.

    That object/function was only defined when the developer tools were open. Otherwise you would get an exception (but of course you couldn't see that exception in any place).

    Daily effect was funny: When you forgot a console.log in your code your page JS would hang. When you tried to debug it by opening the developer tools everything worked- and you started to doubt your sanity pretty soon.

    I wasted hours of my life with that.

  • by d33 on 2/25/18, 8:21 AM

    Obligatory: https://bugs.launchpad.net/ubuntu/+source/cupsys/+bug/255161

    I wonder if at one point we'll end up with a crisis that will make us see excessive complexity as a bug on its own.

  • by michaelmcmillan on 2/25/18, 1:32 PM

    Reminds me of the "can't send mail more than 500 miles" bug. Fantastic read: http://web.mit.edu/jemorris/humor/500-miles
  • by EliRivers on 2/25/18, 10:51 AM

    These (and bugs of other types) can make fantastic war stories for interviews. I have a few such stories from my own experience that I am practiced in telling; they're a really good opportunity to showcase your technical chops in puzzling situations, and also show that you're a personable character able to communicate effectively on technical issues, and an opportunity to demonstrate real enthusiasm and engagement.

    The hook "Tell me about an interesting bug you had to fix" or similar is absolute gold; if you've got a good one lined up, you can dazzle with your diagnostic procedure and explain what you tried and thought of and discounted, showing a wide range of technical expertise and more general investigative procedure. Tell it well and lead them through it, and they will start coming up with ideas and suggestions, making themselves part of the discussion. Ideally, they'll even tell you about something similar they once had to deal with. By the end of the five minute story-telling, you're more than just interviewer-interviewee.

    I plan ahead for these; I have three interesting (well, as interesting as these things get) crazy bug stories ready to go, delivery practiced, and I'll pick one based on other factors of the interview. They're also good for non-interviews; meeting someone at a conference or when working with another company - it's an interesting conversation that the other person can feel involved in and enjoy listening to, and by the end of it you're in their mind as a competent person, good at the job, who is also engaging and communicative and fun to chat to. Because it's true! If you've got interesting material, and you can deliver it well and engagingly, you are all those things. It's not even a trick!

    If you don't plan ahead, you're planning to fail (is the kind of aphorism that makes me want to punch someone but I grudgingly accept is true).

  • by lordnacho on 2/25/18, 9:01 AM

    Every coder at some stage has run into this, right?

    - A bug that disappears when you try to add some cout<< lines.

    - Everything looks correct in debug, where (as mentioned) the variables are initialised to nice values like 0. When you compile with -O3, you get really large values instead.

    - A bug that is rare enough that you have to run the program for a long while before it happens. And when it does, you haven't logged the relevant information.

    - A bug that only manifests when you're not trying to show a colleague.

  • by DandyDev on 2/25/18, 10:44 AM

    Obligatory link to this classic blog post explaining heisenbug and many other classic programming puns: http://www.dodgycoder.net/2011/11/yoda-conditions-pokemon-ex...
  • by jpatokal on 2/25/18, 11:47 AM

    My little contribution to the genre's literature: https://gyrovague.com/2015/07/29/crashes-only-on-wednesdays/
  • by gardarh on 2/25/18, 1:15 PM

    Reminds me of the time I decided to always start using braces for if statements. I was figuring out why this line didn't work:

      if(condition)
         doSomething()
    
    And naturally the obvious thing do to was to add a debugging statement:

      if(condition)
        logSomething()
        doSomething()
    
    And if I remember correctly all of a sudden the bug didn't exist anymore for the condition I was reviewing. Took me a while to figure out what was going on. Lesson learned: Just always use braces.
  • by dmoreno on 2/25/18, 8:26 PM

    I loved the heisenbug/bohrbug distinction in the zen of Erlang [1]:

    > Basically, a bohrbug is a bug that is solid, observable, and easily repeatable. They tend to be fairly simple to reason about. Heisenbugs by contrast, have unreliable behaviour that manifests itself under certain conditions...

    It continues talking that for some kind of heisenbugs, one smart strategy is just to restart to a known state, and forget about this one in a million failures (let it crash).

    [1] https://ferd.ca/the-zen-of-erlang.html

  • by mercer on 2/25/18, 10:59 AM

    Reminds me of "The Zen Of Erlang": https://ferd.ca/the-zen-of-erlang.html
  • by bookofjoe on 2/25/18, 2:23 PM

    Software equivalent of pain that brings you to a doctor's office that disappears upon medical examination.
  • by blaze33 on 2/25/18, 12:22 PM

    Reminds me of the people who couldn't send email farther than 500 miles.

    https://www.ibiblio.org/harris/500milemail.html

  • by dboreham on 2/25/18, 3:18 PM

    I transitioned over from hardware design long ago. We had a similar concept where the circuit would work, but only when an oscilloscope probe is attached at the right place..
  • by knocte on 2/25/18, 10:12 AM

    If you hate heisenbugs, use Functional Programming (or data-race-safe langs such as Rust). It will kill 99.99% of them.