Safely close the connection if an IOException happens during upgrade