fix more cases where the thread may hang