tls: fix handling of failed connects