azure-sdk-for-net: Unable to receive deferred dead-letter from session-enabled queue

I’ve a session-enabled queue with a message in DLQ and the state of the message is “Deferred”. I use the “ReceiveDeferredMessageAsync()” method to receive the message but it fails with the exception “Azure.Messaging.ServiceBus.ServiceBusException: 'The session lock has expired on the MessageSession. Accept a new MessageSession.”.

I don’t think session locks are required for DLQ. Kindly suggest.

Here’s the repro step:

C#

var serviceBusClient = new ServiceBusClient("<connectionstring>");
var serviceBusReceiver = serviceBusClient.CreateReceiver("<queue>", new ServiceBusReceiverOptions
{
    ReceiveMode = ServiceBusReceiveMode.PeekLock,
    SubQueue = SubQueue.DeadLetter
});

var message = await serviceBusReceiver.ReceiveDeferredMessageAsync(<sequence number>);

Exception:

Azure.Messaging.ServiceBus.ServiceBusException: ‘The session lock has expired on the MessageSession. Accept a new MessageSession. TrackingId:8d745660-ceed-4806-9c39-8bd2b0c63875_B3, SystemTracker:NoSystemTracker, Timestamp:2023-03-02T06:47:29 (SessionLockLost). For troubleshooting information, see https://aka.ms/azsdk/net/servicebus/exceptions/troubleshoot.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

The service team is looking into this.

I was able to reproduce the issue when using a separate receiver/client as you mentioned when attempting the final receive:

  await using var client = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString);
  await using var sender = client.CreateSender(scope.QueueName);

  await sender.SendMessageAsync(ServiceBusTestUtilities.GetMessage("sessionId"));

  var receiver = await client.AcceptNextSessionAsync(scope.QueueName);
  var message = await receiver.ReceiveMessageAsync();
  await receiver.DeadLetterMessageAsync(message);

  var deadLetterReceiver = client.CreateReceiver(scope.QueueName, new ServiceBusReceiverOptions
  {
      SubQueue = SubQueue.DeadLetter
  });

  var deadLetterMessage = await deadLetterReceiver.ReceiveMessageAsync();
  await deadLetterReceiver.DeferMessageAsync(deadLetterMessage);

  await using var client2 = new ServiceBusClient(TestEnvironment.ServiceBusConnectionString);

  var deadLetterReceiver2 = client2.CreateReceiver(scope.QueueName, new ServiceBusReceiverOptions
  {
      SubQueue = SubQueue.DeadLetter
  });

 // this throws SessionLockLost
  var deferred = await deadLetterReceiver2.ReceiveDeferredMessageAsync(deadLetterMessage.SequenceNumber);
  Assert.IsNotNull(deferred);

I’ll need to reach out to the service team to find out why this is happening.