Race condition with shutting down