Bot stops responding after some time.
Bot Info
- SDK Platform: .Net Framework 4.6
- SDK Version: 3.14
- Active Channels: Web Chat, Cortana, Skype
- Deployment Environment: Azure App Service
Issue Description
After some time, my bot fails to respond. I cannot say definitively if it's an hour, but is around that time. The only way to correct issue is to restart service. I did recently upgrade to the latest version, but not sure if this is the cause. I also added BotAuth, but have taken it out and issue still occurs. The error that I see in my event log is this.
| Event time | 3/15/2018 9:36:02 AM |
|---|---|
| Message | POST to FosterCareAssistant failed: POST to the bot's endpoint failed with HTTP status 500 POST to the bot's endpoint failed with HTTP status 500 |
| Exception type | System.Exception |
| Failed method | Microsoft.Bot.ChannelConnector.BotAPI+ |
{ "message": "An error has occurred.", "exceptionMessage": "Operation returned an invalid status code 'Unauthorized'", "exceptionType": "Microsoft.Bot.Connector.ErrorResponseException", "stackTrace": " at Microsoft.Bot.Connector.Conversations.
Code Example
Reproduction Steps
- Wait for an hour or so 2. 3.
Expected Behavior
Bot responds.Actual Results
I'm also having this issue. Sometimes not even restarting the service works and I have to republish the bot. Looks like a token in the connector is getting invalidated after a while.
Just now I've set the App Service as Always On to see if it fixes the issue. If that suffices, I'll let you know.
No, it didn't work :( I really have no clue how to proceed. I've already searched and nothing works.
We are currently investigating this issue with .NET BotBuilder sdk v3.14
Related issue: https://github.com/Microsoft/BotBuilder/issues/4321
Just got something similar on the Node.js SDK 3.14.0. I implemented periodic token refresh similar to this https://blog.botframework.com/2017/11/02/optimizing-latency-bot-framework/. However at some point, getAccessToken started throwing the following error
Error: unable to verify the first certificate
at TLSSocket.<anonymous> (_tls_wrap.js:1103:38)
at emitNone (events.js:105:13)
at TLSSocket.emit (events.js:207:7)
at TLSSocket._finishInit (_tls_wrap.js:637:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:467:38)
All subsequent calls to bot connector failed after that until I restarted the server.
Having the exact same issue with version 3.14.0.7
I don't know if it's an hour or perhaps even more. Perhaps related to some internal token that expires after an hour if /api/messages is not called?
In any case I am experiencing the same thing, every morning for example. The service is not "dead", it just doesn't send back responses to questions (mine is a Q&A bot). I can tell from a log that the questions are coming in, I just don't get a reply in e.g. "Test in Web Chat" utility on Azure or DirectLine channel for that matter.
Does anyone know if it helps to downgrade some nuget packages, and if so which ones to downgrade?
@JakobMadsen717 I downgraded one of my bot code instances to 3.13.1 and it's quite stable. Here's my approach;
- Downgraded first
- Started the project locally
- Waited for over one hour
- Tried to interact with bot through the emulator and it responded.
You can give it a try :)
Downgrading to Microsoft.Bot.Builder v3.13.1 did not make a difference to me, there must be something else wrong. After downgrading and deploying, I successfully asked the chatbot a few questions, no problems, then left it alone for 1.5-2 hours, and after that it will not respond (until I restart the App Service). Again, the App Service remains "alive", I can see traces like this in Insight: 1:17:31 PM | Trace @RD00155XXXXXX MessagesController.Post received 'message' with text 'What's the meaning of life?'
It just will not answer after a good long sleep.
You will need to downgrade both Microsoft.Bot.Builder and Microsoft.Bot.Connector to 3.13.1 that is working fine with me till now.
The team is actively working a fix for this. Until we get a release out, please downgrade to v3.13.1.
After downgrading both Microsoft.Bot.Builder and Microsoft.Bot.Connector to 3.13.1 it seems to work fine again. Thanks ahattab & EricDahlvang!
wow, I was trying for hours to find the error, understand how to debug this... and then it turns out to be the framework itself?!
While it is already acknowledged, I wanted to share that even I faced this issue as well.. Maybe 3.14 should have never seen the day of light! I had to even downgrade WindowsAzure.Storage as well to bring in the required Azure Storage state service...
Any ETA on the release of the fixed version?
Bot Info
- SDK Platform: .NET
- SDK Version: 3.14.1.1
- Active Channels: Direct Line
- Deployment Environment: Azure App Service
Issue Description
I have the same problem, using ASP.NET Core 2.0 and Microsoft.Bot.Connector.AspNetCore 2.0.1.3.
Microsoft.Bot.Connector.ErrorResponseException:
at Microsoft.Bot.Connector.Conversations+1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeActionMethodAsync>d__12.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextActionFilterAsync>d__10.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeInnerFilterAsync>d__14.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext (Microsoft.AspNetCore.Routing, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware+<Invoke>d__7.MoveNext (Microsoft.AspNetCore.Cors, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext (Microsoft.AspNetCore.Authentication, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware+<Invoke>d__11.MoveNext (Microsoft.AspNetCore.Server.IISIntegration, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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 System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware+<Invoke>d__3.MoveNext (Microsoft.AspNetCore.Hosting, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
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.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame1+
Code Example
/// <summary>
/// Reply with a message
/// </summary>
private async Task ReplyMessage(Activity activity, string message)
{
// Set application credentials
MicrosoftAppCredentials appCredentials = new MicrosoftAppCredentials(this.options.MicrosoftAppId, this.options.MicrosoftAppPassword);
// Create a client
ConnectorClient client = new ConnectorClient(new Uri(activity.ServiceUrl), appCredentials);
// Create a replay
Activity reply = activity.CreateReply();
// Set the message to return
reply.Text = message;
// Reply to the client
try
{
await client.Conversations.ReplyToActivityAsync(reply);
}
catch(Exception ex)
{
// Log the exception
this.logger.LogError(ex, $"ReplyToActivityAsync: {reply.Text}", null);
}
} // End of the ReplyMessage method
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 ?
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
@JakobMadsen717 I'm facing the same problem with "3.14.0.7". When I upgrade it to "3.14.1.1", my bot works but hava another problem as below. Steps:
- Wait for an hour or so
- Input 'hi' to my bot and 'stack is empty' is thrown.
(Error messages are the same as "3.14.0.7". ) 3.Input 'hi' to my bot again and this time it works. (close the browser) ...... - Wait for an hour or so (open the browser )
- Input 'hi' to my bot and 'stack is empty' is thrown.
(Error messages are the same as "3.14.0.7". ) 6.Input 'hi' to my bot again and this time it works.
If I close the browser (using Edge) after step 3, and open the browser (using Edge) before step 5, the error message is: 'stack is empty'. (Using Chrome is OK). If I do not close the browser (using Edge or Chrome) after step 3, and I will get this error message 'Operation returned an invalid status code 'Unauthorized'.
left : version 3.14.1.1".
right : version 3.14.0.7".

I am facing the same issue with v3.15.2.2. After every one hour whenever I try to interact for the first time it throws the same exception "Operation returned an invalid status code 'Unauthorized'". However, when I send the second message it starts working automatically. It's reproducible after every hour. It happens with both webchat and facebook.
I found a solution maybe work for whom got unauthorized exception when bot service is idle. You need to refresh token and pass it to DelegatingHandler when creating BotConnector.
var account=new MicrosoftAppCredentials("{MicrosoftAppIdKey}", "{MicrosoftAppPasswordKey}");
var jwtToken=await account.GetTokenAsync();
var connector = new ConnectorClient(new Uri("{serviceUrl}"), handlers :new MyDelegatingHandler(jwtToken));
public class MyDelegatingHandler : DelegatingHandler
{
private string _token;
public MyDelegatingHandler(string token)
{
_token = token;
}
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _token);
return base.SendAsync(request, cancellationToken);
}
}
For more detail, please refer to this post https://stackoverflow.com/questions/42749982/initiate-a-message-from-bot-to-user-on-botframework