Skip to content
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: 1 addition & 0 deletions BREAKING_CHANGES_V1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ of `Behavior`, `Wire`, `API` (combine with `+`).

| Status | PR / Branch | Component | Type | Change | Migration |
|--------|-------------|-----------|------|--------|-----------|
| Planned | [#8666](https://github.com/akkadotnet/akka.net/pull/8666) | `Akka.Cluster` (serialization) | Behavior | Cluster.conf's two serializers (`ClusterMessageSerializer`, `ReliableDeliverySerializer`) are now built from an internal module table ahead of reflection, with `Akka.DynamicTypeLoading` on as well as off; the table calls each class's only constructor. With the switch on, two things differ: (1) a `serialization-settings.<alias>` block for either serializer now builds it instead of throwing `MissingMethodException`, since neither constructor takes a `Config`; (2) an exception from either constructor is no longer wrapped in `TargetInvocationException`. With the switch off, both rows -- and the binding for `Akka.Delivery.Internal.IDeliverySerializable`, a type in `Akka.dll` that Cluster's table resolves without reflection -- now resolve instead of throwing `ConfigurationException`. Same mechanism as #8658. | None. Code that caught `MissingMethodException` or `TargetInvocationException` around `ActorSystem.Create` for these serializers should catch the inner exception type instead. |
| Planned | [#8649](https://github.com/akkadotnet/akka.net/pull/8649) | `Akka.Hosting` | Behavior + API | `WithExtension<T>()` and `WithExtensions(params Type[])` now pass extensions to the `ActorSystem` through an `ExtensionsSetup` instead of writing their type names into `akka.extensions`, and Hosting no longer reads `akka.extensions` itself. `Settings.Config.GetStringList("akka.extensions")` therefore no longer lists Hosting-registered extensions; a user-supplied `akka.extensions` reaches core unchanged, so an entry that does not resolve is now logged by core even when `WithExtension` is used (Hosting used to drop it silently), and an extension id whose constructor throws now fails startup with a `ConfigurationException` naming it, instead of being logged and skipped. `WithExtension<T>` gains `[DynamicallyAccessedMembers(PublicParameterlessConstructor)]` on `T`; `WithExtensions(params Type[])` gains `[RequiresUnreferencedCode]`. | Code that inspects `akka.extensions` to find Hosting-registered extensions should read `Settings.Setup.Get<ExtensionsSetup>()` or call `HasExtension<T>()`. Trim/AOT apps should use `WithExtension<T>()`. |
| Planned | [#8658](https://github.com/akkadotnet/akka.net/pull/8658) | `Akka.Remote` / `Akka.Streams` (serialization) | Behavior | Remote.conf's seven serializers and Akka.Streams' `StreamRefSerializer` are now built from internal module tables ahead of reflection, with `Akka.DynamicTypeLoading` on as well as off, and each table calls the class's only constructor. With the switch on, three things differ: (1) a `serialization-settings.<alias>` block for any of the six Remote serializers that take `(system)` or for `akka-stream-ref` now builds the serializer instead of throwing `MissingMethodException`; (2) an empty `serialization-settings.primitive {}` builds `PrimitiveSerializers` with `use-legacy-behavior` off instead of throwing `MissingMethodException`, and a config with no `primitive` block at all (no Remote.conf fallback) now throws `ConfigurationException("configuration is null")` instead; (3) an exception from one of these constructors is no longer wrapped in `TargetInvocationException`. With the switch off, these rows now resolve instead of throwing `ConfigurationException`. A versioned name for a different Akka.Remote/Akka.Streams version resolves both ways; reflection already accepted one (measured with `Version=0.9.0.0` and `Version=99.0.0.0`). | None. Code that caught `MissingMethodException` or `TargetInvocationException` around `ActorSystem.Create` for these serializers should catch the inner exception type instead. |
| Merged | [#8660](https://github.com/akkadotnet/akka.net/pull/8660) | `Akka.IO` | API | Removed `Tcp.ResumeWriting`, `Tcp.WritingResumed`, the `useResumeWriting` parameter and `UseResumeWriting` property on `Tcp.Register`, and the `useResumeWriting` parameter on `TcpMessage.Register` and `TcpMessage.ResumeWriting()`. This NACK-style write-suspend/resume mode was copied from JVM Akka's message shapes but never implemented in Akka.NET: `TcpConnection` never read `Register.UseResumeWriting`, never suspended writes, and never sent `WritingResumed`; `ResumeWriting` was a no-op. | Delete the `useResumeWriting` argument from `Register`/`TcpMessage.Register` calls and any `ResumeWriting` sends. Use ack-based writes (`Tcp.Write.Create(data, ack)`) for write backpressure instead. |
Expand Down
140 changes: 140 additions & 0 deletions src/core/Akka.Cluster.Tests/Serialization/ClusterSerializersSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//-----------------------------------------------------------------------
// <copyright file="ClusterSerializersSpec.cs" company="Akka.NET Project">
// Copyright (C) 2009-2025 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Cluster.Configuration;
using Akka.Cluster.Routing;
using Akka.Cluster.Serialization;
using Akka.Configuration;
using Akka.Delivery;
using Akka.Serialization;
using Akka.TestKit;
using FluentAssertions;
using Xunit;
using AkkaSerialization = Akka.Serialization.Serialization;

namespace Akka.Cluster.Tests.Serialization
{
/// <summary>
/// AppContext switches are process-wide, so a spec that flips <c>Akka.DynamicTypeLoading</c> never runs beside another.
/// </summary>
[CollectionDefinition(Name, DisableParallelization = true)]
public sealed class DynamicTypeLoadingCollection
{
public const string Name = "Akka.DynamicTypeLoading";
}

/// <summary>
/// Keeps <see cref="ClusterSerializers"/> in sync with Cluster.conf. The shared checks live in
/// <see cref="ModuleSerializerSpecs"/>; this spec adds what is specific to Cluster, including the internal
/// API needed to force a reflection-only baseline for the parity comparison below.
/// </summary>
[Collection(DynamicTypeLoadingCollection.Name)]
public class ClusterSerializersSpec : AkkaSpec
{
private const string SwitchName = "Akka.DynamicTypeLoading";

private static readonly Config ClusterProvider = ConfigurationFactory.ParseString("akka.actor.provider = cluster");

private static readonly ModuleSerializerTable NoModules = new(new Dictionary<string, Func<ModuleSerializers?>>());

private static readonly Config ClusterRows = ClusterConfigFactory.Default();

private static readonly Type[] BoundSamples =
{
typeof(ClusterHeartbeatSender.Heartbeat), typeof(ClusterRouterPool), typeof(ConsumerController.Delivery<int>)
};

public ClusterSerializersSpec(ITestOutputHelper output) : base(ClusterProvider, output)
{
}

private static AkkaSerialization Build(ActorSystem system, ModuleSerializerTable table, bool dynamicTypeLoading)
{
var hadSwitch = AppContext.TryGetSwitch(SwitchName, out var previous);
AppContext.SetSwitch(SwitchName, dynamicTypeLoading);
try
{
return new AkkaSerialization((ExtendedActorSystem)system, table);
}
finally
{
AppContext.SetSwitch(SwitchName, !hadSwitch || previous);
}
}

[Fact(DisplayName = "ClusterSerializers should resolve every Cluster.conf row to the type and serializer reflection does")]
public void Should_match_reflection_When_resolving_every_Cluster_conf_row()
{
var table = new ClusterSerializers();
ModuleSerializerSpecs.AssertTableMatchesConfig(ClusterRows, table.Serializers.Select(s => s.Type), table.BoundTypes);

// core's module map names Akka.Cluster, and ClusterSerializers is what it loads for it
ModuleSerializerTable.Default.ForAssembly("Akka.Cluster").Should().NotBeNull();

var reflected = Build(Sys, NoModules, dynamicTypeLoading: true);
var fromTable = Build(Sys, ModuleSerializerTable.Default, dynamicTypeLoading: true);
var settings = Sys.Settings.Config.GetConfig("akka.actor.serialization-settings");
var aliasByType = ModuleSerializerSpecs.SerializerRows(ClusterRows)
.ToDictionary(r => Type.GetType(r.TypeName, throwOnError: true)!, r => r.Alias);

foreach (var (type, create) in table.Serializers.Select(s => (s.Type, s.Create)))
{
var built = create((ExtendedActorSystem)Sys, settings.GetConfig(aliasByType[type]));
built.Should().BeOfType(reflected.GetSerializerById(built.Identifier).GetType(), type.Name);
fromTable.GetSerializerById(built.Identifier).Should().BeOfType(type, type.Name);
}

foreach (var type in BoundSamples)
fromTable.FindSerializerForType(type).Should().BeOfType(reflected.FindSerializerForType(type).GetType(), type.FullName);
}

[Fact(DisplayName = "ClusterSerializers should list no serializer or type that Cluster.conf does not")]
public void Should_have_a_Cluster_conf_row_When_the_table_lists_a_type()
{
var table = new ClusterSerializers();
ModuleSerializerSpecs.AssertTableMatchesConfig(ClusterRows, table.Serializers.Select(s => s.Type), table.BoundTypes);
}

[Fact(DisplayName = "Serialization should resolve Cluster.conf rows spelled as Akka.Hosting writes them when dynamic type loading is off")]
public async Task Should_resolve_assembly_qualified_names_When_dynamic_type_loading_is_disabled()
=> await ModuleSerializerSpecs.AssertHostingSpellingResolves("cluster-aqn", ClusterRows, Sys, BoundSamples);

[Fact(DisplayName = "Serialization should let application.conf override a reference.conf row when dynamic type loading is off")]
public async Task Should_honor_an_application_override_When_it_rebinds_a_Cluster_type()
{
var overrides = ConfigurationFactory.ParseString(
@"akka.actor.serialization-bindings { ""Akka.Delivery.Internal.IDeliverySerializable, Akka"" = bytes }");

await ModuleSerializerSpecs.WithSystem("cluster-override", overrides, ClusterRows, system =>
{
var serialization = ModuleSerializerSpecs.BuildDefault(system, dynamicTypeLoading: false);

serialization.FindSerializerForType(typeof(ConsumerController.Delivery<int>)).Should().BeOfType<ByteArraySerializer>();
serialization.FindSerializerForType(typeof(ClusterHeartbeatSender.Heartbeat)).Should().BeOfType<ClusterMessageSerializer>();
});
}

[Fact(DisplayName = "Serialization should build every Cluster serializer under its usual id, without a warning, when dynamic type loading is off")]
public async Task Should_keep_the_Cluster_serializer_ids_When_dynamic_type_loading_is_disabled()
{
var serialization = await ModuleSerializerSpecs.AssertBuildsWithoutWarning(Sys, EventFilter);

serialization.GetSerializerById(5).Should().BeOfType<ClusterMessageSerializer>();
serialization.GetSerializerById(36).Should().BeOfType<ReliableDeliverySerializer>();

serialization.FindSerializerForType(typeof(ClusterHeartbeatSender.Heartbeat)).Should().BeOfType<ClusterMessageSerializer>();
serialization.FindSerializerForType(typeof(ClusterRouterPool)).Should().BeOfType<ClusterMessageSerializer>();
serialization.FindSerializerForType(typeof(ConsumerController.Delivery<int>)).Should().BeOfType<ReliableDeliverySerializer>();
}
}
}
36 changes: 36 additions & 0 deletions src/core/Akka.Cluster/Serialization/ClusterSerializers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//-----------------------------------------------------------------------
// <copyright file="ClusterSerializers.cs" company="Akka.NET Project">
// Copyright (C) 2009-2025 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2025 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

#nullable enable
using System;
using System.Collections.Generic;
using Akka.Cluster.Routing;
using Akka.Delivery.Internal;
using Akka.Serialization;

namespace Akka.Cluster.Serialization
{
/// <summary>
/// INTERNAL API. The serializer and binding rows of Cluster.conf, so they resolve without reflection.
/// </summary>
internal sealed class ClusterSerializers : ModuleSerializers
{
// the constructor reflection picks for Cluster.conf; each class has one constructor, so it always gets that one
public override IReadOnlyList<ModuleSerializer> Serializers { get; } = new[]
{
new ModuleSerializer(typeof(ClusterMessageSerializer), (system, _) => new ClusterMessageSerializer(system)),
new ModuleSerializer(typeof(ReliableDeliverySerializer), (system, _) => new ReliableDeliverySerializer(system)),
};

public override IReadOnlyList<Type> BoundTypes { get; } = new[]
{
typeof(IClusterMessage),
typeof(ClusterRouterPool),
typeof(IDeliverySerializable),
};
}
}
1 change: 1 addition & 0 deletions src/core/Akka/Serialization/ModuleSerializers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ internal sealed class ModuleSerializerTable
// one entry per module, each passing its own literal to Load so the trimmer can see the type
["Akka.Remote"] = () => Load("Akka.Remote.Serialization.RemoteSerializers, Akka.Remote"),
["Akka.Streams"] = () => Load("Akka.Streams.Serialization.StreamsSerializers, Akka.Streams"),
["Akka.Cluster"] = () => Load("Akka.Cluster.Serialization.ClusterSerializers, Akka.Cluster"),
});

private readonly Dictionary<string, Func<ModuleSerializers?>> _modules;
Expand Down
Loading