Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/UiPath.CoreIpc/Transport/Tcp/TcpClientTransport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Net.Sockets;

namespace UiPath.Ipc.Transport.Tcp;

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

internal sealed class TcpClientState : IClientState
{
private System.Net.Sockets.TcpClient? _tcpClient;
private TcpClient? _tcpClient;

public Stream? Network { get; private set; }

Expand All @@ -34,7 +35,7 @@ public async ValueTask Connect(IpcClient client, CancellationToken ct)
{
var transport = client.Transport as TcpClientTransport ?? throw new InvalidOperationException();

_tcpClient = new System.Net.Sockets.TcpClient();
_tcpClient = new();
#if NET461
using var ctreg = ct.Register(_tcpClient.Dispose);
try
Expand All @@ -47,7 +48,21 @@ public async ValueTask Connect(IpcClient client, CancellationToken ct)
throw new OperationCanceledException(ct);
}
#else
await _tcpClient.ConnectAsync(transport.EndPoint.Address, transport.EndPoint.Port, ct);
// ported from support/v21.10 (https://github.com/UiPath/coreipc/pull/119)
while (true)
{
ct.ThrowIfCancellationRequested();
try
{
await _tcpClient.ConnectAsync(transport.EndPoint, ct);
break;
}
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionRefused)
{
await Task.Delay(10, ct);
}
}

#endif
Network = _tcpClient.GetStream();
}
Expand Down