I'm using
await stream.AuthenticateAsServerAsync(serverCert, true, SslProtocols.Tls, false);
In my application to secure a coection. Unfortunately in rare cases (roughly one out of 1000) this hangs completely. I tried to set timeouts on the lower level NetworkStream and the TcpClient.
But nothing works, those coections keep accumulating over time.
And by it hangs completely I mean it gets stuck inside there for days (if the application runs that long).
I currently solved this with a dirty hack. Im starting a new thread, wait 5seconds inside it, and if the call didnt retu in time I call tcpClient.Close() to force the SslStream to abort.
Whats the issue here? What is the intended way to handle scenarios like this in general where you need a timeout on a function but there is no overload that takes a TimeSpan or CancellationToken?
Shouldnt the lower level timeouts on the tcpClient at least throw an exception? Why is that not happening either?
