fixed client socket not being closed in the main thread