[networking] make tls code more robust;