Skip to content

Commit 79f9bc6

Browse files
Fix serialize-messages=on DeadLetter inside DeadLetter bug (#7236)
* Fix serialize-messages=on DeadLetter inside DeadLetter bug * Fix solution --------- Co-authored-by: Aaron Stannard <[email protected]>
1 parent 3c61f46 commit 79f9bc6

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/core/Akka/Actor/ActorCell.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,17 +533,23 @@ private Envelope SerializeAndDeserialize(Envelope envelope)
533533
object deserializedMsg;
534534
try
535535
{
536-
deserializedMsg = SerializeAndDeserializePayload(envelope.Message);
536+
deserializedMsg = SerializeAndDeserializePayload(unwrapped);
537537
}
538538
catch (Exception e)
539539
{
540540
throw new SerializationException($"Failed to serialize and deserialize payload object [{unwrapped.GetType()}]. Envelope: [{envelope}], Actor type: [{Actor.GetType()}]", e);
541541
}
542542

543-
// special case handling for DeadLetters
544-
return envelope.Message is DeadLetter deadLetter
545-
? new Envelope(new DeadLetter(deserializedMsg, deadLetter.Sender, deadLetter.Recipient), envelope.Sender)
546-
: new Envelope(deserializedMsg, envelope.Sender);
543+
// Check that this message was ever wrapped
544+
if (ReferenceEquals(envelope.Message, unwrapped))
545+
return new Envelope(deserializedMsg, envelope.Sender);
546+
547+
// In the case above this one, we're able to deserialize the message, and we returned that
548+
// (a new copy of the message), however, when we're dealing with wrapped messages, it's impossible to
549+
// reconstruct the russian dolls together again, so we just return the original envelope.
550+
// We guarantee that we can de/serialize in innermost message, but we can not guarantee to return
551+
// a new copy.
552+
return envelope;
547553
}
548554
#nullable restore
549555

src/core/Akka/Event/DeadLetter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public sealed class DeadLetter : AllDeadLetters
8383
/// </exception>
8484
public DeadLetter(object message, IActorRef sender, IActorRef recipient) : base(message, sender, recipient)
8585
{
86+
System.Diagnostics.Debug.Assert(message is not DeadLetter, "DeadLetter inside DeadLetter");
8687
if (sender == null) throw new ArgumentNullException(nameof(sender), "DeadLetter sender may not be null");
8788
if (recipient == null) throw new ArgumentNullException(nameof(recipient), "DeadLetter recipient may not be null");
8889
}

0 commit comments

Comments
 (0)