botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Bot returns "Operation returned an invalid status code 'Unauthorized'" when invoking context.PostAsync

Open hpksp opened this issue 8 years ago • 23 comments

Bot Info

  • SDK Platform: .NET
  • SDK Version: 3.14.0.7
  • Active Channels: Cortana ,WebChat
  • Deployment Environment: Azure App Service (East US, East US 2, West Europe)

Issue Description

I'm getting "Operation returned an invalid status code 'Unauthorized'" when trying to invoke context.PostAsync. This happens in both development environment and azure web apps. Bot functions perfectly in the first hour or so once it's being run locally or deployed to azure. The error occurs when the project is being running for over 1 hour. When this happens the bot clients get the Internal Server Error 500. I managed to isolate the problem by using App Insight. If I restart the server when this happens Bot starts to function again.

Reproduction Steps

  1. Run bot
  2. Interact with bot, works fine
  3. Wait for 1 hour
  4. Interact with bot again, get the error

Additional Info

  • I'm using Document DB for state management which is hosted in (East US)
  • Using LUIS (US)

StackTrace

System.Exception {Microsoft.Bot.Connector.ErrorResponseException}

Microsoft.Bot.Connector.ErrorResponseException: Operation returned an invalid status code 'Unauthorized' at Microsoft.Bot.Connector.Conversations.d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Connector.ConversationsExtensions.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.InputHintQueue.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.AutoInputHint_BotToUser.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.MapToChannelData_BotToUser.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.LogBotToUser.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.d__12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Extensions.d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at AFBot.Dialogs.RootDialog.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.<Rest>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop-PollAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult() at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.<Rest>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait-PollAsync>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop<C>-PollAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop-PollAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.d__23.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ScoringEventLoop`1.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.EventLoopDialogTask.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.SetAmbientThreadCulture.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Bot.Builder.Dialogs.Conversation.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at AFBot.MessagesController.d__0.MoveNext()

hpksp avatar Mar 15 '18 09:03 hpksp

Same problem with Luis and other channels (Telegram, Facebook Messenger and Skype). Because of this problem I recreated all project and services and my approved skype bot is not working anymore because of a bug in channel registration that doesn´t allow me to edit the skype channel properties. The url is https://botzapprices4.azurewebsites.net

JonesAbramoff avatar Mar 16 '18 00:03 JonesAbramoff

I am having the same issue. I am using Document DB for state management which is hosted in (East US) along with the Direct Line Channel. As stated by HPKSP this seems to be an intermittent issue. My service is hosted on my own server.

1Click1Life avatar Mar 17 '18 16:03 1Click1Life

@1Click1Life I think this is the same as issue: https://github.com/Microsoft/BotBuilder/issues/4322. Check that one out, is has a temp solution.

JakobMadsen717 avatar Mar 17 '18 17:03 JakobMadsen717

Thanks for the fast response ... I will check it out. Thanks.

1Click1Life avatar Mar 17 '18 17:03 1Click1Life

Problem seems to be in SDK version 3.14.0.7. Downgrading both Microsoft.Bot.Builder and Microsoft.Bot.Connector to version 3.13.1 would solve the problem until Bot Framework team come up with a fix.

hpksp avatar Mar 19 '18 09:03 hpksp

I'm facing the same problem with Microsoft.Bot.Builder version="3.14.0.7" Microsoft.Bot.Connector version="3.14.0.7"

using DirectLine channel and hosting the service on premise.

@EricDahlvang any ETA to fix this issue ?

ederbond avatar Mar 21 '18 11:03 ederbond

Eder,

Siga a sugestão acima de usar a versao 3.13.1 no bot builder e tb no bot connector e acompanhe o https://github.com/Microsoft/BotBuilder/issues/4322 .

JonesAbramoff avatar Mar 21 '18 12:03 JonesAbramoff

We have pushed a new version of the SDK which includes a fix for this issue https://www.nuget.org/packages/Microsoft.Bot.Builder/3.14.1.1

JasonSowers avatar Mar 21 '18 17:03 JasonSowers

Not yet solved with 3.14.1.1

RStraviso avatar Apr 06 '18 07:04 RStraviso

@RStraviso

You may have been experiencing this issue: https://github.com/Microsoft/BotBuilder/issues/4432 The underlying Azure AAD problem has been resolved. Please follow along there for updates.

EricDahlvang avatar Apr 06 '18 16:04 EricDahlvang

Hi there, I'm still getting this error sporadically - are there any news on this (the version is 3.15.2.1)? Thanks

apollondeveloper avatar May 12 '18 15:05 apollondeveloper

Me too with 3.15.2.2 .

JonesAbramoff avatar Jun 04 '18 12:06 JonesAbramoff

Upgrade to 3.15.2.2 and still getting this error

blrchen avatar Jun 11 '18 09:06 blrchen

MicrosoftAppCredentials.TrustServiceUrl(activity.ServiceUrl); this code works~

shunyh avatar Jun 12 '18 07:06 shunyh

I have tried MicrosoftAppCredentials.TrustServiceUrl with 3.15.2.2 and a few times a day it doesn´t work.

JonesAbramoff avatar Jun 12 '18 14:06 JonesAbramoff

@JonesAbramoff @blrchen @apollondeveloper

Can you please post in this issue I created #4733 With the following details:

  1. Frequency - How often is this happening? Every message? Randomly and how often ex. 1 out of 10 messages
  2. What channels is this happening on, is it working on any channels?
  3. Stack trace
  4. Deployment where is this happening - Local testing? Azure? Both?

if not locally 5. Type of bot Functions bot? Web App bot? 6. Is there any relevant info in app insights? 7. Timestamp and conversation ID when this occurs?

JasonSowers avatar Jun 12 '18 18:06 JasonSowers

We have released a new package 3.15.2.3 that we believe addresses this issue. Please let us know if you are still experiencing this issue after upgrading. in #4733

JasonSowers avatar Jun 28 '18 16:06 JasonSowers

@JasonSowers Could you release Microsoft.Bot.Builder.Azure for Microsoft.Bot.Builder v3.15.2.3? When I updated to Microsoft.Bot.Builder v3.15.2.3 then a runtime error which is FileNotFoundException occurred.

The file which didn't find is as below:

Microsoft.Bot.Connector, Version=3.15.2.2, Culture=neutral, PublicKeyToken=31bf3856ad364e35

I'm using on the Azure Functions.

runceel avatar Jul 06 '18 16:07 runceel

@runceel I brought this issue up yesterday. I would expect that we will be doing so in the near future. I will keep pressing for this to be released with the other packages in our nightly build.

JasonSowers avatar Jul 06 '18 16:07 JasonSowers

@JasonSowers OK. Thanks :)

runceel avatar Jul 06 '18 16:07 runceel