close the socket in the worker function