Reaching for Food to Avoid pain and discomfort in pushing forward my work

Hello there! I have been struggling with the urges of going to the kitchen and reaching for snacks when I am faced with pain and discomfort when the software that I am programming is encountering problems and I feel stuck and not knowing how to solve the problems. The feeling makes feel like a failure because professional success is my number one priority right now, yet I keep leaving the desk and taking a snack break whenever I encounter a problem that I think is going to take a long time to solve. I have been trying to allow the discomfort and pain to sink in and resist the urge to go to get a snack, but it’s not working so far. Please advise.