Make shutdown wait for exit properly.