Here’s why they happen and how to get ahead of them.