sammydeprez
sammydeprez

Reputation: 55

Microsoft Bot Framework v4 Random 'Unauthorized' error on initial conversation

We built a bot for a customer in the latest Bot SDK, but we get randomly 'Unauthorized' errors on the start of the conversation.

See error below, what is quite strange because:

  1. It doesn't happen often
  2. And the error is send from the bot, so the DirectLine API already communicated with the bot, but the bot cant send anything back to the DirectLine. (this is something we assume, but hard to debug)

We are still on MemoryStorage, but don't think this has anything todo with it.

Framework Version:

Anyone a solution for this

Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'
   at Microsoft.Bot.Connector.Conversations.ReplyToActivityWithHttpMessagesAsync(String conversationId, String activityId, Activity activity, Dictionary`2 customHeaders, CancellationToken cancellationToken)
   at Microsoft.Bot.Connector.ConversationsExtensions.ReplyToActivityAsync(IConversations operations, String conversationId, String activityId, Activity activity, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass22_0.<<SendActivitiesAsync>g__SendActivitiesThroughAdapter|1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(IActivity activity, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(String textReplyToSend, String speak, String inputHint, CancellationToken cancellationToken)
   at Louise.Chatbot.DialogSteps.GreetingDialogSteps.GreetUserAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) in C:\Users\.......\GreetingDialogSteps.cs:line 26
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.OnStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.RunStepAsync(DialogContext dc, Int32 index, DialogReason reason, Object result, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.Dialogs.WaterfallDialog.BeginDialogAsync(DialogContext dc, Object options, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.Dialogs.DialogContext.BeginDialogAsync(String dialogId, Object options, CancellationToken cancellationToken)
   at Louise.Chatbot.Louise.OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken) in C:\Users\.......\Louise.cs:line 154
   at Microsoft.Bot.Builder.MiddlewareSet.ReceiveActivityWithStatusAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)
   at Microsoft.Bot.Builder.BotAdapter.RunPipelineAsync(ITurnContext turnContext, BotCallbackHandler callback, CancellationToken cancellationToken)

Upvotes: 1

Views: 829

Answers (1)

CoHealer
CoHealer

Reputation: 40

Per [https://github.com/Microsoft/botbuilder-dotnet/issues/1251][1]

"The likely cause here is a token caching bug in the v4 SDK. Last release, in the V3 C# SDK, we moved away from our custom code and over to a turnkey solution offered by the AAD team. So far, that seems to have been working quite well, and we're comfortable with the solution. As a nice side effect of this work, performance under very high load is also quite a bit better.

The work is under way right now in the v4 C# SDK and is planned in the 4.3 release in mid Feb."

Upvotes: 2

Related Questions