question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to receive deferred dead-letter from session-enabled queue

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JoshLove-msftcommented, Mar 8, 2023

The service team is looking into this.

1reaction
JoshLove-msftcommented, Mar 6, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Service Bus - Dead-letter queues
Deferred messages will not be purged and moved to the dead-letter queue after they expire. This behavior is by design.
Read more >
Enable dead lettering for Azure Service Bus queues and ...
This article explains how to enable dead lettering for queues and subscriptions by using Azure portal, PowerShell, CLI, and programming ...
Read more >
Azure Service Bus client library for .NET
In order to receive deferred messages, the sequence number of the message needs to be retained. DeadLetter - moves the message to the...
Read more >
Azure Service Bus queue messages got stuck
I recently created some partitioned queues from where I send and receive all the time. They've run as non-partitioned in the past without...
Read more >
Azure Service Bus and its Complete Overview
Deferred mode of message processing ensures the messages are not lost due to any network outage or if a user doesn't perform resubmission...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found