Fix a bug when shutdown is requested.