Properly handle sleeps interrupted by receiving a message