Safely close the connection if an IOException happens during upgrade
Ensure the SSL channel is closed even on socket error