[Issue 10101] Fix double file close when first TLS connection fails