Skip to content

Conversation

andradf
Copy link

@andradf andradf commented Sep 17, 2025

What this PR does / why we need it:
ServiceBusReceiver.PeekMessageAsync does not necessarily respect the cancellation token. See Azure/azure-sdk-for-net#52620. This causes the SB Queue and Subscription health checks to not return. In production environments where request timeouts and output cache for health endpoints are vital to avoiding health check cascading and DDOS attacks, this limitation prevents the usual request timeout and output caching patterns in AspNet Core from operating correctly.
To get around this, this PR fails the health check if the receiver.PeekMessage does not return before the cancellation token is triggered.

Which issue(s) this PR fixes:
Please reference the issue this PR will close: #2432

Does this PR introduce a user-facing change?: No

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly (The Dapr project fails due to deprecated dependency warnings, but that issue is already present in master)
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing
  • Extended the documentation
  • Provided sample for the feature

ServiceBusReceiver.PeekMessageAsync does not necessarily respect the
cancellation token.
See Azure/azure-sdk-for-net#52620.
To get around this limitation, we create a task with the cancellation
token and use WhenAny to return on cancel even if the receiver hasn't
returned.
We also add tests to validate the correct behavior.
@andradf
Copy link
Author

andradf commented Sep 17, 2025

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service Bus queue and subscription health check does not respect cancellation token

1 participant