Destroy socket when an error occurs