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

Have ShardingAdapter recursively call the underlying IMessageExtractor #7474

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

Aaronontheweb
Copy link
Member

@Aaronontheweb Aaronontheweb commented Jan 17, 2025

Changes

close #7470

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

Copy link
Member Author

@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.

Detailed my changes

@@ -76,7 +76,7 @@ public ExtractorAdapter(IMessageExtractor underlying)
{
return message switch
{
ShardingEnvelope se => se.Message,
ShardingEnvelope se => _underlying.EntityMessage(se.Message),
Copy link
Member Author

Choose a reason for hiding this comment

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

Also call the underlying message extractor's EntityMessage method on the payload of the ShardingEnvelope, just in case that also needs unwrapping. This is needed in order to make sure that messages still work properly when using tools like Akka.Cluster.Sharding.Delivery, which uses the ShardingEnvelope heavily.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do a recursive search here instead, just to make doubly sure?

something in the line of

private object UnwrapShardingEnvelope(object message)
{
  object unwrapped = message;
  while(unwrapped is IWrappedMessage)
  {
    if(unwrapped is ShardingEnvelope)
      return unwrapped;
    unwrapped = unwrapped.Message;
  }
  return message;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

No because that's introducing side-effects the user is ultimately responsible for - we only care about the ShardingEnvelope specifically

Copy link
Contributor

@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.

Something to think about

@@ -76,7 +76,7 @@ public ExtractorAdapter(IMessageExtractor underlying)
{
return message switch
{
ShardingEnvelope se => se.Message,
ShardingEnvelope se => _underlying.EntityMessage(se.Message),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do a recursive search here instead, just to make doubly sure?

something in the line of

private object UnwrapShardingEnvelope(object message)
{
  object unwrapped = message;
  while(unwrapped is IWrappedMessage)
  {
    if(unwrapped is ShardingEnvelope)
      return unwrapped;
    unwrapped = unwrapped.Message;
  }
  return message;
}

Copy link
Contributor

@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.

LGTM

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) January 17, 2025 22:04
@Aaronontheweb
Copy link
Member Author

Looks like this introduced a real test failure

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.

Akka.Cluster.Sharding: can't recursively unpack ShardingEnvelope contents in IMessageExtractor
2 participants