Skip to content

Commit b82ab2c

Browse files
fix(node-runtime): abandon message on InvalidOperationException
The MessageProcessingService was catching InvalidOperationException without abandoning the message, causing test failures. Added abandon logic to the InvalidOperationException handler to match the behavior of the generic Exception handler. Fixes: ProcessMessage_WithUnexpectedException_ShouldAbandon test
1 parent a279661 commit b82ab2c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Node.Runtime/Services/MessageProcessingService.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ private async Task ProcessSingleMessageAsync(ReceivedMessage message, Cancellati
293293
stopwatch.Stop();
294294
_logger.LogError(invalidOpEx, "Invalid operation while processing MessageId={MessageId}", message.MessageId);
295295

296+
// For unexpected InvalidOperationExceptions, abandon the message for retry
297+
try
298+
{
299+
await _inputConnector.AbandonMessageAsync(message, cancellationToken);
300+
}
301+
catch (Azure.Messaging.ServiceBus.ServiceBusException abandonEx) when (abandonEx.Reason == Azure.Messaging.ServiceBus.ServiceBusFailureReason.MessageLockLost)
302+
{
303+
_logger.LogWarning("Cannot abandon MessageId={MessageId} - lock already lost", message.MessageId);
304+
}
305+
catch (InvalidOperationException)
306+
{
307+
_logger.LogWarning("Cannot abandon MessageId={MessageId} - already settled", message.MessageId);
308+
}
309+
296310
activity?.SetStatus(ActivityStatusCode.Error, invalidOpEx.Message);
297311
activity?.AddEvent(new ActivityEvent("exception",
298312
tags: new ActivityTagsCollection

0 commit comments

Comments
 (0)