Skip to content

Fix serialize-messages=on DeadLetter inside DeadLetter bug #7236

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

Merged
merged 3 commits into from
Jun 7, 2024
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
16 changes: 11 additions & 5 deletions src/core/Akka/Actor/ActorCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,23 @@ private Envelope SerializeAndDeserialize(Envelope envelope)
object deserializedMsg;
try
{
deserializedMsg = SerializeAndDeserializePayload(envelope.Message);
deserializedMsg = SerializeAndDeserializePayload(unwrapped);
}
catch (Exception e)
{
throw new SerializationException($"Failed to serialize and deserialize payload object [{unwrapped.GetType()}]. Envelope: [{envelope}], Actor type: [{Actor.GetType()}]", e);
}

// special case handling for DeadLetters
return envelope.Message is DeadLetter deadLetter
? new Envelope(new DeadLetter(deserializedMsg, deadLetter.Sender, deadLetter.Recipient), envelope.Sender)
: new Envelope(deserializedMsg, envelope.Sender);
// Check that this message was ever wrapped
if (ReferenceEquals(envelope.Message, unwrapped))
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

return new Envelope(deserializedMsg, envelope.Sender);

// In the case above this one, we're able to deserialize the message, and we returned that
// (a new copy of the message), however, when we're dealing with wrapped messages, it's impossible to
// reconstruct the russian dolls together again, so we just return the original envelope.
// We guarantee that we can de/serialize in innermost message, but we can not guarantee to return
// a new copy.
return envelope;
}
#nullable restore

Expand Down
1 change: 1 addition & 0 deletions src/core/Akka/Event/DeadLetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public sealed class DeadLetter : AllDeadLetters
/// </exception>
public DeadLetter(object message, IActorRef sender, IActorRef recipient) : base(message, sender, recipient)
{
System.Diagnostics.Debug.Assert(message is not DeadLetter, "DeadLetter inside DeadLetter");
Copy link
Member

Choose a reason for hiding this comment

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

LGTM

if (sender == null) throw new ArgumentNullException(nameof(sender), "DeadLetter sender may not be null");
if (recipient == null) throw new ArgumentNullException(nameof(recipient), "DeadLetter recipient may not be null");
}
Expand Down