In my previous life as a developer, I would get asked to stay late and work. This happened for only two reasons:
Now, I want the projects I work on to succeed. I want the products I build to live up to the hype I am told about. I want to be a part of that story.
I will not, however, suffer to see that happen.
Regardless of which of the two reasons it is that is causing the late night, the problem is that deep down you, the developer, are being asked to cover up problem as quickly as you can. This countermeasure will lead to further problems that will in turn lead to late nights.
The reason is super simple. Whatever the issue is you’re being asked to burn the midnight oil on, isn’t actually the problem. It’s just a symptom. So you deal with the symptom, the problem remains. Maybe the way deadlines are set are ridiculous (When has that happened?!). Maybe the production issue isn’t as severe as it’s made out to be, or was identified and ignored earlier, or is genuinely new. The problem is that fixing that issue doesn’t close the gap that allowed it in, and almost never protects you from that exact same thing happening again.
So this is hard. Fixing this issue is something you want to do, are being asked to do by your superior, and you know that you shouldn’t fall victim to the emergency at hand.
Next time this happens, tell your manager they need to stay with you for support. They will say they have no idea how to help you (There’s a clue right there), and you can tell them you need them to get you food, drink, and help you stay relaxed.
Make them stay with you. Make them suffer with you. Sharing the burden of this problem will make people have more visibility to the reality that something more sinister is at play. Tell them that the next day at work, you are going to spend as much time really finding and fixing the real problem. If it was high enough priority to cause a late night, it’s a high enough priority to really fix.
If you have a manager that is unkind about this, and threatens you. Try to remember they are trying too, explain the issue, ask for them to work with you. If they are unrelenting, you should find a new job. You deserve better leadership and a better life. In the mean time, tell them you’ll work, but inform them you’ll be drinking heavily, and maybe you may cause more harm than good (I have actually done this with success).