fix the error with closing the socket