Closing socket in the background properly