[threadpool] Fix hang on threadpool cleanup (#4330)