TcpStreamFactory.Connect method uses sync socket.Connect with timer-based cancellation on another thread, which in some rare cases leads to dead-locks on Linux and Mac in case of cancellation/timeout occurred while Socket is being connection.
We can use socket.ConnectAsync with combination of Task.Wait to mitigate the problem. Even though calling async method from sync code path is not a recommended way, it could be acceptable here as socket is being connected not that often.