Debugging 101

Cracking Bugs

13
By Dara Vesper
Engineering

Every one of us runs into bugs that feel utterly impossible to diagnose. The nastiest to debug are the intermittent, inconsistent kind. How do you fix something that only misbehaves now and then? When a line of code fails every time, the fix is straightforward. The system is linear. The failure is reproducible.

‍

How do you debug an intermittent bug? How do you debug something that works only sometimes?

‍

Here are a few reminders to my future self for the next baffling debugging session.

‍

Choose to Learn

‍

The biggest lessons I've ever picked up came out of debugging. Every bug is a doorway to understanding the system more deeply. If I already knew what was behind the problem, there'd be no bug to speak of. The very fact that I'm staring at a bug I can't obviously fix means, by definition, there's something here for me to learn.

‍

The system is handing me a gift: the chance to learn.

‍

Choose to seize that chance to learn.

‍

Hunt the Error

‍

Answer this question: "how do I get this to fail every single time?"

‍

Rather than keep coaxing the system into working, do the opposite: make it fail. Charge straight at the error. Amplify it. Crank up the error rate. Set it off again and again.

‍

Concentrate on driving the error rate to 100%. Only then can I be sure any success came from my action, not randomness.

‍

Make predictions to check my understanding: "The system will fail, now (pushes button)"

‍

Pare Down

‍

Once I can summon the error on demand, I start isolating. I begin whittling down the steps that trigger it. Cut steps out or hard-code responses. Trim away any complexity that isn't needed to cause the error.

‍

If reproducing it takes 6 steps, try switching each one off in turn.

‍

Hunt for the fewest degrees of freedom that still reproduce the error.

‍

Check the Inverse

‍

Reminder: the error isn't caused by something I understand. Look deliberately at the spots where I assume the system is working.

‍

Which pieces of the system am I certain are working? What if they aren't behaving the way I think? Actually verify that those components do what I expect them to.

‍

Reminder: it isn't the things we don't know that trip us up, it's the things we're certain of that just aren't so

‍

Craft a Conclusive Measure

‍

Brainstorm which report, metric, log, or data point would flat-out reveal what's causing the error. It may not tell me "why" the error happens, but it can nudge me closer to "where" it's being caused.

‍

Question: which single piece of information would conclusively reveal what the problem is?

‍

Take a Pause

‍

I could well be making things worse. If I don't know what's causing the error, I can't know whether I'm worsening it. When the situation allows, step away for a bit.

‍

Grab some air. Go for a walk. Breathe.

‍

A clear, relaxed mind welcomes new ideas.

‍

Sleep on it. Return to it tomorrow.

‍

Explain the Repro Steps

‍

Speak it aloud.

Talk it through.

Walk through each repro step.

Begin at the very start.

Back up three steps and say it again.

Slower this round.

‍

Wrap-up

‍

With any luck this helps you crack an issue you've been wrestling with. Got other techniques or tweaks to these? Let me know on Chirpwave: @daravesper

‍

For those who skip to the end, here's the tldr:

‍

  1. Choose to Learn
  2. Hunt the Error
  3. Pare Down
  4. Check the Inverse
  5. Craft a Conclusive Measure
  6. Take a Pause
  7. Explain the Repro Steps

‍

Get posts by email

Drop in your email and we'll ping you the next time something new goes up. Expect roughly ~1-2x per month, plus the occasional monthly note about company news.

Fork and ship a hello world project to Nimbric in less time than it took to read this page. Feel the power.

Deploy on Nimbric 🚀

Deploy on Nimbric