Skip to content
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

Shared future bug tests #1970

Merged
merged 4 commits into from
Apr 28, 2023
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
dotnet:
- net7.0
- net6.0
- netcoreapp3.1
test:
- "tests/Proto.Cluster.Tests/*.csproj"
- "tests/Proto.Cluster.PartitionIdentity.Tests/*.csproj"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
dotnet:
- net7.0
- net6.0
- netcoreapp3.1
test:
- "tests/Proto.Cluster.Tests/*.csproj"
- "tests/Proto.Cluster.PartitionIdentity.Tests/*.csproj"
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/RemoteBenchmark/Node2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ private static async Task Main()
)
);

#if NETCOREAPP3_1
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
#endif


Console.WriteLine("Enter Advertised Host (Default = 127.0.0.1)");
var advertisedHost = Console.ReadLine().Trim();
Expand Down
10 changes: 9 additions & 1 deletion src/Proto.Actor/Future/SharedFuture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ public void Dispose()
Interlocked.Increment(ref _createdRequests);
_onStarted?.Invoke();

return new SharedFutureHandle(this, pid, requestSlot.CompletionSource!);
var cs = requestSlot.CompletionSource!;

// //TODO: can this happen?
// if (cs.Task.IsCanceled)
// {
// throw new Exception("SharedFuture bug, Task is canceled");
// }

return new SharedFutureHandle(this, pid, cs);
}

protected internal override void SendUserMessage(PID pid, object message)
Expand Down
22 changes: 4 additions & 18 deletions src/Proto.Actor/Mailbox/Mailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public static IMailbox Create(params IMailboxStatistics[] stats) =>
new DefaultMailbox(new LockingUnboundedMailboxQueue(4), new UnboundedMailboxQueue(), stats);
}

public sealed class DefaultMailbox : IMailbox
#if NET5_0_OR_GREATER
, IThreadPoolWorkItem
#endif
public sealed class DefaultMailbox : IMailbox, IThreadPoolWorkItem

{
private readonly IMailboxStatistics[] _stats;
private readonly IMailboxQueue _systemMessages;
Expand Down Expand Up @@ -307,29 +305,17 @@ private void Schedule()
{
if (_dispatcher == Dispatchers.DefaultDispatcher)
{
#if NET5_0_OR_GREATER
ThreadPool.UnsafeQueueUserWorkItem(this, false);
#else
ThreadPool.UnsafeQueueUserWorkItem(RunWrapper, this);
#endif
}
else
{
_dispatcher.Schedule(() => RunAsync(this));
}
}
}

#if NET5_0_OR_GREATER

public void Execute() => _ = RunAsync(this);
#else
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void RunWrapper(object state)
{
var y = (DefaultMailbox)state;
RunAsync(y);
}
#endif

}

/// <summary>
Expand Down
10 changes: 9 additions & 1 deletion src/Proto.Actor/PID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ internal PID(string address, string id, Process process) : this(address, id)

internal Process? CurrentRef { get; private set; }

public string ToDiagnosticString() => $"{Address}/{Id}";
public string ToDiagnosticString()
{
if (RequestId > 0)
{
return $"{Address}/{Id}:{RequestId}";
}

return $"{Address}/{Id}";
}

/// <summary>
/// Creates a new PID instance from address and identifier.
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Actor/Proto.Actor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<LangVersion>10</LangVersion>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Cluster.AmazonECS/Proto.Cluster.AmazonECS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.ResourceManager.AppContainers" Version="1.0.1"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Cluster.Consul/Proto.Cluster.Consul.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Consul" Version="1.6.10.7" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<LangVersion>10</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<RootNamespace>Proto.Cluster.Consul</RootNamespace>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
Expand Down
59 changes: 1 addition & 58 deletions src/Proto.Cluster/DefaultClusterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
Expand All @@ -24,9 +23,6 @@ public class DefaultClusterContext : IClusterContext

private readonly PidCache _pidCache;
private readonly ShouldThrottle _requestLogThrottle;
#if !NET6_0_OR_GREATER
private readonly TaskClock _clock;
#endif
private readonly ActorSystem _system;
private static readonly ILogger Logger = Log.CreateLogger<DefaultClusterContext>();
private readonly int _requestTimeoutSeconds;
Expand All @@ -47,12 +43,6 @@ public DefaultClusterContext(Cluster cluster)

_requestTimeoutSeconds = (int)config.ActorRequestTimeout.TotalSeconds;
_legacyTimeouts = config.LegacyRequestTimeoutBehavior;
#if !NET6_0_OR_GREATER
var updateInterval =
TimeSpan.FromMilliseconds(Math.Min(config.ActorRequestTimeout.TotalMilliseconds / 2, 1000));
_clock = new TaskClock(config.ActorRequestTimeout, updateInterval, cluster.System.Shutdown);
_clock.Start();
#endif
}

public async Task<T?> RequestAsync<T>(ClusterIdentity clusterIdentity, object message, ISenderContext context,
Expand Down Expand Up @@ -115,12 +105,8 @@ public DefaultClusterContext(Cluster cluster)
{
context.Request(pid, message, future.Pid);
var task = future.Task;

#if NET6_0_OR_GREATER

await task.WaitAsync(CancellationTokens.FromSeconds(_requestTimeoutSeconds)).ConfigureAwait(false);
#else
await Task.WhenAny(task, _clock.CurrentBucket).ConfigureAwait(false);
#endif

if (task.IsCompleted)
{
Expand Down Expand Up @@ -335,49 +321,6 @@ private async ValueTask RemoveFromSource(ClusterIdentity clusterIdentity, PidSou
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static (ResponseStatus Ok, T?) ToResult<T>(PidSource source, ISenderContext context, object result)
{
var message = MessageEnvelope.UnwrapMessage(result);

if (message is DeadLetterResponse)
{
if (!context.System.Shutdown.IsCancellationRequested && Logger.IsEnabled(LogLevel.Debug))
{
Logger.LogDebug("TryRequestAsync failed, dead PID from {Source}", source);
}

return (ResponseStatus.DeadLetter, default);
}

if (message == null)
{
return (ResponseStatus.Ok, default);
}

if (message is T t)
{
return (ResponseStatus.Ok, t);
}

if (typeof(T) == typeof(MessageEnvelope))
{
return (ResponseStatus.Ok, (T)(object)MessageEnvelope.Wrap(result));
}

Logger.LogError("Unexpected message. Was type {Type} but expected {ExpectedType}", message.GetType(),
typeof(T));

return (ResponseStatus.InvalidResponse, default);
}

private enum ResponseStatus
{
Ok,
InvalidResponse,
DeadLetter
}

private enum PidSource
{
Cache,
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Cluster/Proto.Cluster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc.Tools" Version="2.51.0" PrivateAssets="All" />
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.OpenTelemetry/Proto.OpenTelemetry.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CouchbaseNetClient" Version="2.7.22" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.101.8" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Marten" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.19.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RavenDB.Client" Version="5.3.100" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.12" />
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Persistence/Proto.Persistence.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.Remote/Proto.Remote.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Proto.TestKit/Proto.TestKit.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
Expand Down
6 changes: 2 additions & 4 deletions tests/Proto.Actor.Tests/Diagnostics/DiagnosticsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class DiagnosticsTests
[Fact]
public async Task CanListPidsInProcessRegistry()
{
var system = new ActorSystem();
await using var _ = system;
await using var system = new ActorSystem();
var context = system.Root;

var props = Props.FromProducer(() => new MyDiagnosticsActor());
Expand All @@ -41,8 +40,7 @@ public async Task CanListPidsInProcessRegistry()
[Fact]
public async Task CanGetDiagnosticsStringFromActorDiagnostics()
{
var system = new ActorSystem();
await using var _ = system;
await using var system = new ActorSystem();
var context = system.Root;

var props = Props.FromProducer(() => new MyDiagnosticsActor());
Expand Down
Loading