Fixed loop hang on shutdown