I myself is a programmer who tried applying pomodoro techniques. In your example, I have experienced the same issues:
Once, I nearly complete my code just 2 minutes before a pomodoro round
off. But then I discover a problem, which may take about 5 minutes to
solve... Well, "I'll fix it soon, and just 5 mins is not a problem!" -
I thought so.
After around 15 minutes trying, I realized that I under-estimated the
problem. Instead I created more blunders. It's bad. I'm feeling bad
about my estimation... and my ability. I put it aside & take some
break.
After the break, I come to the computer, revert all my changes & try
fixing the problem again. Suddenly I realize things is far more
simpler that it used to be. It takes 2 minutes.
So I agree with Pomodorium, the pomodoro technique is good because it gives people time, but not only to think, but to relax as well. Focusing too long on a problem will make you weary and cloud the judgement.
Taking break refresh your mind, help you be more conscious.
So, what is the right solution to your example? I often solve that like following:
I spent the last 2 minutes reviewing what I have done (take some note) and what I'm going to do the next phase. This step is also mentioned in pomodoro techniques.
I take a break, and don't think about that problem. I quickly take note that the task take 1 pomodoro longer than expected.
After break, I come back to work, and fix the problem. This should be easy because I have planned it in the last pomodoro. If there's time, I will review how to solve the problem better (if you are not near a deadline, ofcourse :) )
Personally, I think pomodoros should be modified to fit personal use. We are different, so there's no silver bullet for all the people. I'm still trying to do pomodoros... and compare, and review to make it better little by little.