Skip to content

add the active method calls when throwing exception for message too l… #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/CI/azp-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ stages:
- job:
displayName: 'node.js on Ubuntu'
pool:
vmImage: 'ubuntu-20.04'
vmImage: 'ubuntu-22.04'
steps:
- template: azp-initialization.yaml
- template: azp-nodejs.yaml
Expand Down
1 change: 1 addition & 0 deletions src/UiPath.CoreIpc.Tests/ComputingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public ComputingTests()
_computingHost.RunAsync(GuiScheduler);
_computingClient = ComputingClientBuilder(GuiScheduler).SerializeParametersAsObjects().ValidateAndBuild();
}

protected abstract TBuilder ComputingClientBuilder(TaskScheduler taskScheduler = null);
[Fact]
public async Task ReconnectWithEncrypt()
Expand Down
8 changes: 8 additions & 0 deletions src/UiPath.CoreIpc.Tests/NamedPipeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public override void BeforeCallServerSide()
_pipeName = "beforeCall";
base.BeforeCallServerSide();
}

public override void Initialize()
{
}
#if WINDOWS
[Fact]
public async Task PipeSecurityForWindows()
Expand Down Expand Up @@ -50,4 +54,8 @@ protected override NamedPipeClientBuilder<IComputingService, IComputingCallback>
.RequestTimeout(RequestTimeout)
.CallbackInstance(_computingCallback)
.TaskScheduler(taskScheduler);

public override void Initialize()
{
}
}
12 changes: 11 additions & 1 deletion src/UiPath.CoreIpc.Tests/TcpTests..cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ public override async void BeforeCallServerSide()
base.BeforeCallServerSide();
}
IPEndPoint GetEndPoint() => new(IPAddress.Loopback, _port);

public override void Initialize()
{
_port = GetAvailablePort();
}
}
public class ComputingTcpTests : ComputingTests<TcpClientBuilder<IComputingService, IComputingCallback>>
{
protected static readonly IPEndPoint ComputingEndPoint = new(IPAddress.Loopback, 2121+GetCount());
public override void Initialize()
{
ComputingEndPoint = new(IPAddress.Loopback, GetAvailablePort());
}

protected IPEndPoint ComputingEndPoint;
protected override TcpClientBuilder<IComputingService, IComputingCallback> ComputingClientBuilder(TaskScheduler taskScheduler = null) =>
new TcpClientBuilder<IComputingService, IComputingCallback>(ComputingEndPoint, _serviceProvider)
.RequestTimeout(RequestTimeout)
Expand Down
15 changes: 15 additions & 0 deletions src/UiPath.CoreIpc.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,25 @@ public abstract class TestBase : IDisposable
//}
public TestBase()
{
Initialize();

_guiThread.SynchronizationContext.Send(() => Thread.CurrentThread.Name = "GuiThread");
_serviceProvider = IpcHelpers.ConfigureServices();
}

public int GetAvailablePort()
{
var endPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, 0);
var listener = new System.Net.Sockets.TcpListener(endPoint);
listener.Start();
int port = ((System.Net.IPEndPoint)listener.LocalEndpoint).Port;
listener.Stop();

return port;
}

public abstract void Initialize();

protected static int GetCount() => Interlocked.Increment(ref Count);

protected TaskScheduler GuiScheduler => _guiThread.Scheduler;
Expand Down
13 changes: 11 additions & 2 deletions src/UiPath.CoreIpc.Tests/WebSocketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,33 @@ public override void Dispose()
[Fact]
public override async void BeforeCallServerSide()
{
_port++;
_port = GetAvailablePort();
base.BeforeCallServerSide();
}
#if !NET461
[Fact(Skip = "WebSocket.State is unreliable")]
public override Task UploadNoRead() => base.UploadNoRead();
#endif
string GetEndPoint() => $"://localhost:{_port}/";
public override void Initialize()
{
_port = GetAvailablePort();
}
}
public class ComputingWebSocketsTests : ComputingTests<WebSocketClientBuilder<IComputingService, IComputingCallback>>
{
protected static readonly string ComputingEndPoint = $"://localhost:{1212+GetCount()}/";
protected string ComputingEndPoint;
HttpSysWebSocketsListener _listener;
protected override WebSocketClientBuilder<IComputingService, IComputingCallback> ComputingClientBuilder(TaskScheduler taskScheduler = null) =>
new WebSocketClientBuilder<IComputingService, IComputingCallback>(new("ws"+ComputingEndPoint), _serviceProvider)
.RequestTimeout(RequestTimeout)
.CallbackInstance(_computingCallback)
.TaskScheduler(taskScheduler);

public override void Initialize()
{
ComputingEndPoint = $"://localhost:{GetAvailablePort()}/";
}
protected override ServiceHostBuilder Configure(ServiceHostBuilder serviceHostBuilder)
{
_listener = new HttpSysWebSocketsListener("http" + ComputingEndPoint);
Expand Down
3 changes: 2 additions & 1 deletion src/UiPath.CoreIpc/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Connection(Stream network, ISerializer serializer, ILogger logger, string
internal async ValueTask<Response> RemoteCall(Request request, CancellationToken token)
{
var requestCompletion = Rent();
requestCompletion.MethodName = request.MethodName;
var requestId = request.Id;
_requests[requestId] = requestCompletion;
var tokenRegistration = token.UnsafeRegister(_cancelRequest, requestId);
Expand Down Expand Up @@ -211,7 +212,7 @@ private async Task ReceiveLoop()
var length = BitConverter.ToInt32(_buffer, startIndex: 1);
if (length > _maxMessageSize)
{
throw new InvalidDataException($"Message too large. The maximum message size is {_maxMessageSize / (1024 * 1024)} megabytes.");
throw new InvalidDataException($"Message too large. {Environment.NewLine} The maximum message size is {_maxMessageSize / (1024 * 1024)} megabytes. {Environment.NewLine} Active method calls: {string.Join(Environment.NewLine, _requests.Values.Select(r => r.MethodName))}");
}
_nestedStream.Reset(length);
await HandleMessage();
Expand Down
1 change: 1 addition & 0 deletions src/UiPath.CoreIpc/TaskCompletionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal static class TaskCompletionPool<T>
public sealed class ManualResetValueTaskSource : IValueTaskSource<T>, IValueTaskSource
{
private ManualResetValueTaskSourceCore<T> _core; // mutable struct; do not make this readonly
public string MethodName { get; set; }
public bool RunContinuationsAsynchronously { get => _core.RunContinuationsAsynchronously; set => _core.RunContinuationsAsynchronously = value; }
public short Version => _core.Version;
public ValueTask<T> ValueTask() => new(this, Version);
Expand Down