Microsoft.Azure.ServiceBus.UnauthorizedException

Syamala, UdayKumar 31 Reputation points
2021-06-22T06:10:11.653+00:00

Getting the following error all of a sudden at the subscriber of a topic while reading message-
The issue is occurred earlier and it is resolved after a day without making any changes.

Haven't found any issues with the connection string, this is worked earlier and this error is occurring all of a sudden.

Microsoft.Azure.ServiceBus.UnauthorizedException
Put token failed. status-code: 401, status-description: Unauthorized TrackingId:460b83ec-0c8e-40fd-932d-eb8029a88190_G14

Failed Method : Microsoft.Azure.ServiceBus.Core.MessageReceiver+<OnReceiveAsync>d__88.MoveNext

Call Stack:
Microsoft.Azure.ServiceBus.UnauthorizedException:
at Microsoft.Azure.ServiceBus.Core.MessageReceiver+<OnReceiveAsync>d__88.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.Core.MessageReceiver+<>c__DisplayClass65_0+<<ReceiveAsync>b__0>d.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.RetryPolicy+<RunOperation>d__19.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.RetryPolicy+<RunOperation>d__19.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.Core.MessageReceiver+<ReceiveAsync>d__65.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.Core.MessageReceiver+<ReceiveAsync>d__63.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.Azure.ServiceBus.MessageReceivePump+<<MessagePumpTaskAsync>b__12_0>d.MoveNext (Microsoft.Azure.ServiceBus, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c)

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
548 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JayaC-MSFT 5,526 Reputation points
    2021-06-22T12:21:32.243+00:00

    Hello @Syamala, UdayKumar , Welcome to Microsoft QnA. Thank you for the question.

    I am glad that your issue has been resolved. I see similar discussions which might help in this case:

    https://www.pmichaels.net/tag/put-token-failed-status-code-401/
    https://github.com/Azure/azure-service-bus/issues/182
    https://stackoverflow.com/questions/43347605/event-hub-error-put-token-failed-status-code-401-status-description-expired/65534986#65534986

    However, if you want a proper root cause analysis specific to your application, I would request you to open a support ticket with Microsoft Support if you have a subscription which allows you to do so. Otherwise ,you can send an email with subject line <<removed>> referencing this thread along with the subscription id.


  2. Lavrenty Eskin 1 Reputation point
    2022-06-24T19:30:21.243+00:00

    For me the issue "Put token failed. status-code: 401, status-description: Unauthorized" was caused by the networking configuration of the storage account where Azure Event Hub client persists checkpoints. Both the SA and EH have had whitelisted client address, and it works when I run client app from my laptop (behind the proxy btw). But when the same client deployed to AKS and acting through AKS egress public IP, even this IP whitelisted on the SA and EH, the EH accepts incoming connection, but the SA decline it. I am not sure where the AKS pod inciting connection from, no any logged connection attempts on the SA. When I made SA accept connections from "All networks", the issue "Put token failed. status-code: 401, status-description: Unauthorized" has gone. Microsoft has recommended to deploy SA into another region to have EH and SA in different regions, but I didn´t test it yet, and due to billed traffic I wouldn´t.
    Hope this help.

    0 comments No comments