[Question] A task was cancelled error in context.Postasync() and while sending typing activity
Bot Info
- App ID: https://dev.botframework.com/bots?id=IndigoHRBot (dd5aad30-1988-403a-8bfc-d9338c0bbb48)
- SDK Platform: .NET
- Active Channels: facebook messenger
- Deployment Environment: hosted in company premises
Issue Description
I am getting the task was cancelled error intermittently in two lines of code.
Code Example
await connector.Conversations.ReplyToActivityAsync(isTypingReply); and await context.PostAsync("The flow has been stopped, please type Hi/Hello to start again.");
Reproduction Steps
Happens intermittently, not able to reproduce on will
Actual Results
Getting below errors in the mentioned lines of code
Time: 04-12-2017 12:15:11 PM
Message: A task was canceled.
Stack Trace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
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.ThrowForNonSuccess(Task task)
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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ParentServiceContoller.MessagesController.d__4.MoveNext() in D:\Dev\INDIGOHR_BOT\ParentServiceContoller\Controllers\MessagesController.cs:line 34
Source: mscorlib
Time: 04-12-2017 12:44:56 PM
Message: A task was canceled.
Stack Trace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.Conversations.1.<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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait1.<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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Fiber1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult()
at ParentServiceContoller.Dialogs.RootDialog.<ResumeAfterForwardDialog>d__9.MoveNext() in D:\Dev\INDIGOHR_BOT\ParentServiceContoller\Dialogs\RootDialog.cs:line 211
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-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.IAwaiter1.<ResumeAsync>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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop<C>-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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Base-IEventLoop-PollAsync>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.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IDialogStack-Forward>d__172.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.
please provide minimum code to reproduce so we can better assist you.
@JasonSowers @nwhitmont Please find the minimum code below: await context.PostAsync("The flow has been stopped, please type Hi/Hello to start again.");
Using: MS BOT Framework over Facebook Channel
Thanks in Advance!
@JasonSowers @nwhitmont I am getting this error intermittently in await context.PostAsync() I have used anywhere in code. For your reference I will put one scenario here
I have implemented scorable for STOP/CANCEL/RESTART etc and have below code in CancelScorable calling the CancelDialog to post the message to user and reset the context of NLP
protected override async Task PostAsync(IActivity item, string state, CancellationToken token)
{
var message = item as IMessageActivity;
if (message != null)
{
var cancelDialog = new CancelDialog();
var interruption = cancelDialog.Void<object, IMessageActivity>();
this.task.Call(interruption, null);
await this.task.PollAsync(token);
//message.Text = "I see you want to restart the process, please type Hi/Hello to start again.";
//this.task.Post(message);
}
this.task.Reset();
//this.task.Done(false);
}
code to send the message and reset the NLP context in CancelDialog
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("The flow has been stopped, please type Hi/Hello to start again.");
string ClientAccessToken = System.Configuration.ConfigurationManager.AppSettings["ClientAccessToken"];
var config = new AIConfiguration(ClientAccessToken, SupportedLanguage.English);
config.SessionId = context.Activity.ChannelId + context.Activity.From.Id;
apiAi = new ApiAi(config);
AIRequest airequest = new AIRequest();
airequest.ResetContexts = true;
airequest.Query = new[] { "Cancel" };
var apiaiContextReset = apiAi.TextRequest(airequest);
context.Wait(this.MessageReceived);
}
I am getting the error here in await context.PostAsync("The flow has been stopped, please type Hi/Hello to start again.");
facing similar issues, any help
@Sandeepmahala are you able to put your entire project in a repo for us to look at? There's just not enough here to really help look into this
Facing similar issue..does anyone got the solution / workaround?
I am facing the same issue ... anyone has a solution? I a, using bot builder version 3.11.
putting a try catch around sending the typing activity solved the issue for me.... got the solution from this post. https://stackoverflow.com/questions/47647632/a-task-was-cancelled-error-in-context-postasync-and-while-sending-the-typing-a