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

System.InvalidOperationException: The SessionId was not set on a message on wolverine-ping when sending to an Azure FIFO queue #1230

Open
s11ha opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@s11ha
Copy link

s11ha commented Jan 20, 2025

Describe the bug
While wolverine application is running when queue is latched then in order to resume wolverine sends a "wolverine-ping" envelope.
But if queue is Azure FIFO queue it fails with an error

System.InvalidOperationException: The SessionId was not set on a message, and it cannot be sent to the entity. 
Entities that have session support enabled can only receive messages that have the SessionId set to a valid value.

then it enters into a cycle of being latched, trying to resume, getting this error until app is stopped.

The same error happens when FailureAcknowledgement is being sent. But for FailureAcknowledgement i guess it could be eliminated by using AddOutgoingRule for a FIFO queue wolverine configuration.
I guess the same could happen and with Acknowledgement but I never encountered that.

To Reproduce
I prepared a demo app where a wolverine-ping is simulated because I do not know how to cause it other way.

public async Task<Response> Handle(
    Request request,
    IConfiguration configuration,
    AzureServiceBusTransport azureServiceBusTransport,
    IWolverineRuntime runtime,
    IMessageBus messageBus,
    CancellationToken token
)
{
    var queue = azureServiceBusTransport.Queues[configuration["AsbFifoQueue"]];
    var methodInfo = queue
        .GetType()
        .GetMethod("CreateSender", BindingFlags.Instance | BindingFlags.NonPublic);
    var sender = (ISender)methodInfo.Invoke(queue, [runtime]);
    var sendingAgent = runtime.Endpoints.CreateSendingAgent(
        new Uri("local://replies/"),
        sender,
        queue
    );
    ((ISenderRequiresCallback)sender).RegisterCallback(sendingAgent as ISenderCallback);

    var pingResult = await sender.PingAsync();

    return new Response(pingResult);
}

The full code is here - PingCheck.zip

Steps to reproduce the behavior:

  1. open appsettings.json and specify AsbConnectionString and AsbFifoQueue (name of fifo queue)
  2. dotnet run
  3. navigate to http://localhost:5000/ping
  4. See error in the loop
  5. you also can notice the PingAsync always returns true

Expected behavior
There should not be error

Desktop (please complete the following information):

  • Version [3.6.5]

Additional context

The hotfix is to use Harmony patching library.

[HarmonyPatch(typeof(Envelope), nameof(Envelope.ForPing))]
public class EnvelopeForPingFix
{
    public static void Postfix(ref Envelope __result, Uri destination)
    {
        __result.GroupId = Envelope.PingMessageType;
    }
}

public static class WolverinePingFix
{
    [ModuleInitializer]
    public static void Patch()
    {
        var harmony = new Harmony(nameof(WolverinePingFix));
        var assembly = Assembly.GetExecutingAssembly();
        harmony.PatchAll(assembly);
    }
}

Maybe it can be fixed the same way in wolverine.

public static Envelope ForPing(Uri destination)
{
        return new Envelope
        {
            MessageType = PingMessageType,
            // fix
            GroupId = Envelope.PingMessageType,
            // end fix
            Data = [1, 2, 3, 4],
            ContentType = "wolverine/ping",
            Destination = destination
        };
}
@s11ha s11ha changed the title wolverine-ping cause loop of errors when sending to Azure FIFO queue wolverine-ping causes a loop of errors when sending to an Azure FIFO queue Jan 20, 2025
@s11ha s11ha changed the title wolverine-ping causes a loop of errors when sending to an Azure FIFO queue System.InvalidOperationException: The SessionId was not set on a message on wolverine-ping when sending to an Azure FIFO queue Jan 20, 2025
@jeremydmiller
Copy link
Member

Thanks for the write up here. It's probably going to take less time to do the fix than it did your issue, but only because you did write this up.

@jeremydmiller jeremydmiller added the bug Something isn't working label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants