fix socket close before detection in threads.