Skip to content

Commit d77a4b4

Browse files
port fix TCP connect on Linux (all of .NET Core) from support/v21.10 (#120)
1 parent f6ad51d commit d77a4b4

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/UiPath.CoreIpc/Transport/Tcp/TcpClientTransport.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net;
2+
using System.Net.Sockets;
23

34
namespace UiPath.Ipc.Transport.Tcp;
45

@@ -21,7 +22,7 @@ internal override void Validate()
2122

2223
internal 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

Comments
 (0)