Set a time limit on how long at once you will work on the task, e.g. 2 hours. Once this time is reached and you aren't making progress, take a break for 10-15 minutes which can be going for a walk, eating a snack, chatting with people, whatever besides that problem that can help "reset" your mental focus as after a while, it is useless to try to fix things through brute force.
Make sure you have a clear understanding of what the bug is exactly. There have been times where I'd get a bug that said, "This looks ugly. Please fix," and think, "Where is the spec that I'm supposed to make this look like as I don't know how to make this look good?" sort of thinking. This can also come if you've had to go to someone to referee the finger pointing between developers and testers where each is saying, "I am following the spec." That referee could be a manager, of developers, testers, or projects, but I do feel sorry for those that get pulled into these situations.