Skip to content

[Feature Req] Eagerly signal session lock lost when underlying connection/link fault and signal ProcessSessionMessageEventArgs.CancellationToken #49057

@hpendyalamsft

Description

@hpendyalamsft

Library name and version

Azure.Messaging.ServiceBus 7.18.4

Describe the bug

When using ServiceBusSessionProcessor to process messages from sessions and in the event of SessionLockLost due to ConnectionReset during processing a message M1,we are observing
a new connection is being created immediately and the M1 getting redelivered and processed by a separate invocation of ProcessMessageHandler.

The initial invocation of ProcessMessageHandler processing M1 is unaware of a ConnectionReset event.
Neither SessionLockProcessSessionMessageEventArgs.CancellationToken is getting canceled nor SessionLockLostAsync event is being raised.

This is leading to a situation where there is no way handle an occurence of event like this in our code and
2 instances of M1 are being concurrently processed.

Expected behavior

SessionLock lost due to ConnectionReset should be captured by either SessionLockProcessSessionMessageEventArgs.CancellationToken
or SessionLockLostAsync event and allow us handle this event appropriately in code.

Actual behavior

Neither SessionLockProcessSessionMessageEventArgs.CancellationToken is getting canceled nor SessionLockLostAsync event is being raised
when session-lock is lost due to ConnectionReset.
Any subsequent operation on the message (either settle the message, release session etc.) results in SessionLockLostException due to ConnectionReset.

Reproduction Steps

Attaching a simple project to repro the issue but defining the high level steps here:

  1. Create a queue with sessions enabled and following settings
    MaxDeliveryCount = 10
    DefaultMessageTimeToLive = TimeSpan.FromMinutes(60)
    LockDuration = TimeSpan.FromSeconds(60)
    RequiresSession = true
  1. Queue a message M1 with session S1
  2. Create a ServiceBusSessionProcessor with following settings
    ReceiveMode = ServiceBusReceiveMode.PeekLock
    MaxConcurrentSessions = 5
    MaxConcurrentCallsPerSession = 1
    MaxAutoLockRenewalDuration = Timeout.InfiniteTimeSpan
    AutoCompleteMessages = false
  1. Setup ProcessMessageHandler to honor cancellationToken and listen to SessionLockLostAsync events
  2. Recieve M1
  3. Force close connection using SysInternals-TcpView
  4. Observation: M1 gets redelivered immediately and neither is cancellationToken being canceled nor SessionLockLostAsync being invoked.

SessionLockLostConnectionReset.zip

Environment

.NET SDK:
Version: 8.0.407
Commit: cac65f27eb
Workload version: 8.0.400-manifests.011c56c6
MSBuild version: 17.11.26+2b19be476

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.407\

Host:
Version: 9.0.3
Architecture: x64
Commit: 831d23e561

.NET SDKs installed:
6.0.427 [C:\Program Files\dotnet\sdk]
8.0.407 [C:\Program Files\dotnet\sdk]
9.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Visual Studio : Version 17.13.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue is related to a non-management packageService Buscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.feature-requestThis issue requires a new behavior in the product in order be resolved.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

    Type

    No type

    Projects

    Status

    Planned

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions