More robust graceful shutdown