Skip to content

Commit

Permalink
Fix serialize-messages=on DeadLetter inside DeadLetter bug (#7236)
Browse files Browse the repository at this point in the history
* Fix serialize-messages=on DeadLetter inside DeadLetter bug

* Fix solution

---------

Co-authored-by: Aaron Stannard <aaron@petabridge.com>
  • Loading branch information
Arkatufus and Aaronontheweb authored Jun 7, 2024
1 parent 3c61f46 commit 79f9bc6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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))
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");
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

0 comments on commit 79f9bc6

Please sign in to comment.