This code has a timing issue:
using (cancellationToken.UnsafeRegister(static s => ((Socket)s!).Dispose(), socket))
{
socket.Connect(new DnsEndPoint(host, port));
}
If the socket.Connect call succeeds, but then the CancellationToken fires before the registration is disposed, then the Socket will be disposed but we will still continue as if the Connect succeeded.
I'm reasonably sure that's what caused this failure: https://helix.dot.net/api/2019-06-17/jobs/e63fcc11-e9ad-476c-9798-47f2f6d3b152/workitems/System.Net.Http.Functional.Tests/console