Ensure the SSL channel is closed even on socket error