Close socket, if write error has occurred.