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

Fix StreamRefSerializer NRE bug #7333

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

Arkatufus
Copy link
Contributor

StreamRefSerializer will throw an NRE if ActorMaterializer.DefaultConfig() were added to actor system configuration before ActorSystem is started.

Changes

Remove _serialization field from .ctor and use _system.Serialization instead.

Copy link
Contributor Author

@Arkatufus Arkatufus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review

@@ -37,52 +36,51 @@ public sealed class StreamRefSerializer : SerializerWithStringManifest
public StreamRefSerializer(ExtendedActorSystem system) : base(system)
{
_system = system;
_serialization = system.Serialization;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix. system.Serialization is null if config were added before the ActorSystem is started because all serializer plugins were instantiated before ActorSystem.Serialization is assigned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could make for a decent analyzer rule

@@ -129,7 +127,7 @@ private SequencedOnNext DeserializeSequenceOnNext(byte[] bytes)
{
var onNext = Proto.Msg.SequencedOnNext.Parser.ParseFrom(bytes);
var p = onNext.Payload;
var payload = _serialization.Deserialize(
var payload = system.Serialization.Deserialize(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix. Instead of using a field assigned Serialization, we just retrieve it from _system.Serialization when we need it.

@@ -169,7 +167,7 @@ private ByteString SerializeCumulativeDemand(CumulativeDemand demand) =>
private ByteString SerializeSequencedOnNext(SequencedOnNext onNext)
{
var payload = onNext.Payload;
var serializer = _serialization.FindSerializerFor(payload);
var serializer = system.Serialization.FindSerializerFor(payload);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix. Instead of using a field assigned Serialization, we just retrieve it from _system.Serialization when we need it.

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) September 4, 2024 14:09
@Aaronontheweb Aaronontheweb added this to the 1.5.28 milestone Sep 4, 2024
@Aaronontheweb Aaronontheweb merged commit e8beec4 into akkadotnet:dev Sep 4, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants