11using System . Net ;
2+ using System . Net . Sockets ;
23
34namespace UiPath . Ipc . Transport . Tcp ;
45
@@ -21,7 +22,7 @@ internal override void Validate()
2122
2223internal sealed class TcpClientState : IClientState
2324{
24- private System . Net . Sockets . TcpClient ? _tcpClient ;
25+ private TcpClient ? _tcpClient ;
2526
2627 public Stream ? Network { get ; private set ; }
2728
@@ -34,7 +35,7 @@ public async ValueTask Connect(IpcClient client, CancellationToken ct)
3435 {
3536 var transport = client . Transport as TcpClientTransport ?? throw new InvalidOperationException ( ) ;
3637
37- _tcpClient = new System . Net . Sockets . TcpClient ( ) ;
38+ _tcpClient = new ( ) ;
3839#if NET461
3940 using var ctreg = ct . Register ( _tcpClient . Dispose ) ;
4041 try
@@ -47,7 +48,21 @@ public async ValueTask Connect(IpcClient client, CancellationToken ct)
4748 throw new OperationCanceledException ( ct ) ;
4849 }
4950#else
50- await _tcpClient . ConnectAsync ( transport . EndPoint . Address , transport . EndPoint . Port , ct ) ;
51+ // ported from support/v21.10 (https://github.com/UiPath/coreipc/pull/119)
52+ while ( true )
53+ {
54+ ct . ThrowIfCancellationRequested ( ) ;
55+ try
56+ {
57+ await _tcpClient . ConnectAsync ( transport . EndPoint , ct ) ;
58+ break ;
59+ }
60+ catch ( SocketException ex ) when ( ex . SocketErrorCode == SocketError . ConnectionRefused )
61+ {
62+ await Task . Delay ( 10 , ct ) ;
63+ }
64+ }
65+
5166#endif
5267 Network = _tcpClient . GetStream ( ) ;
5368 }
0 commit comments