Hi
The thread is stuck in the TLS handshake, not waiting for a reply…
As a workaround, add in a connection factory that sets the timeout before connecting.
The broken connection still can’t complete the call, but instead of hanging forever you get an exception after ConnectTimeout seconds catch it, drop the connection and retry.
public class TimeoutAwareSslFactory : HttpsConnectionFactory
{
public TimeoutAwareSslFactory(HttpProxySettings proxy) : base(proxy) { }
public int ConnectTimeout { get; set; } = 15;
public override Connection CreateClientConnection(Binding binding)
{
var inner = new Connection(binding);
inner.Timeout = this.ConnectTimeout;
inner.TimeoutEnabled = true;
if (!this.Enabled) return inner;
var ssl = base.CreateClientConnection(inner);
ssl.Timeout = this.ConnectTimeout;
ssl.TimeoutEnabled = true;
return ssl;
}
}
Then set it on your channel right after you create it:
var factory = new TimeoutAwareSslFactory(channel.ProxySettings);
factory.CopyProperties(channel.SslOptions);
channel.HttpClient.SslOptions = factory;
The timeout was always on by default (60 sec), it simply wasn’t applied during
connect and the TLS handshake.
Now it is, so the call throws instead of hanging.