Shutdown race fixes