Skip to content

Commit d03e3f5

Browse files
Processor improvements (#26904)
* Use the right overload for the ContinueWith in the receiver manager make sure the continuation is actually using ExecuteSynchronously * Update change log * Remove array allocation from linked token source creation * Update changelog
1 parent a9fb359 commit d03e3f5

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Thank you to our developer community members who helped to make the Service Bus
88
- Max Hamulyak _([GitHub](https://github.com/kaylumah))_
99
- Daniel Marbach _([GitHub](https://github.com/danielmarbach))_
1010

11+
### Bugs Fixed
12+
13+
- Fix unnecessary task scheduling in ServiceBusProcessor and ServiceBusSessionProcessor
14+
- Remove array allocation when creating linked token sources from the ServiceBusProcessor
15+
1116
### Features Added
1217

1318
- The `State` property has been added to `ServiceBusReceivedMessage` which indicates whether a message is `Active`, `Scheduled`, or `Deferred`. _(A community contribution, courtesy of [danielmarbach](https://github.com/danielmarbach))_

sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ReceiverManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ private async Task RenewMessageLock(
262262
// by the renewLockCancellationToken. This way we prevent a TaskCanceledException.
263263
Task delayTask = await Task.Delay(delay, cancellationToken)
264264
.ContinueWith(
265-
(t, s) => t,
265+
t => t,
266+
CancellationToken.None,
266267
TaskContinuationOptions.ExecuteSynchronously,
267268
TaskScheduler.Default)
268269
.ConfigureAwait(false);

sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/ServiceBusProcessor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ private async Task RunReceiveTaskAsync(CancellationToken cancellationToken)
812812
// hold onto all the tasks that we are starting so that when cancellation is requested,
813813
// we can await them to make sure we surface any unexpected exceptions, i.e. exceptions
814814
// other than TaskCanceledExceptions
815-
var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
815+
// Instead of using the array overload which allocates an array, we use the overload that has two parameters
816+
// and pass in CancellationToken.None. This should be safe since CanBeCanceled will return false.
817+
var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, CancellationToken.None);
816818

817819
TaskTuples.Add(
818820
(

sdk/servicebus/Azure.Messaging.ServiceBus/src/Processor/SessionReceiverManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ private async Task RenewSessionLock()
350350
// by the renewLockCancellationToken. This way we prevent a TaskCanceledException.
351351
Task delayTask = await Task.Delay(delay, sessionLockRenewalCancellationToken)
352352
.ContinueWith(
353-
(t, s) => t,
353+
t => t,
354+
CancellationToken.None,
354355
TaskContinuationOptions.ExecuteSynchronously,
355356
TaskScheduler.Default)
356357
.ConfigureAwait(false);

0 commit comments

Comments
 (0)