Repository: microsoft/botframework-sdk

Issue #960: HttpOperationException: Precondition Failed after quick messages
Created: 2016-08-10T07:41:58Z
Hello!
So i haven't noticed that exception before and im pretty sure i tried out that scenario:
When i send quick messages to my bot, i get the following exception (With a "Sorry. my bot has a problem")

Microsoft.Rest.HttpOperationException: Precondition Failed    at Microsoft.Bot.Connector.ErrorHandling.HandleError<HttpOperationResponse1 result|ObjectT>    at Microsoft.Bot.Connector.BotStateExtensions.<SetConversationDataAsync>d_9.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.ConnectorStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-SaveAsync>d_3.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<Save>d_10.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-FlushAsync>d_5.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.BotDataBase1.<FlushAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__61.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d_51.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.d_5`1.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Conversation.d_4.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Conversation.d_2.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.GetResult()    at Bot.MessagesController.d__5.MoveNext() in C
9:32 :\Workspace\MyBot\Bot\Controllers\MessagesController.cs:line 95

To cause that exception, i jsut have to send like 3 Messages within 1 or 2 seconds. The 2 last messages arrive at the bot while the first one is still being processed by the bot.
I'm pretty sure I've tried doing that before 3.1, but im not 100% sure.
Has there something changed how the Connector handles messages to a bot, while there is still a message being processed?
Is there a workaround for that?
By the way: The error doesnt occur with the emulator.
Greetings

Duplicate issue #977: Typing activity exception
Created: 2016-08-11T15:53:07Z
I get an exception when trying to handle typing activity. I tried in Slack channel.
Exception: Microsoft.Rest.HttpOperationException: Precondition Failed    at Microsoft.Bot.Connector.ErrorHandling.HandleError<HttpOperationResponse1 result|ObjectT> in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Microsoft.Bot.Connector\ErrorHandling.cs:line 32    at Microsoft.Bot.Connector.BotStateExtensions.<SetConversationDataAsync>d_9.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Microsoft.Bot.Connector\StateAPI\BotStateExtensions.cs:line 227 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.ConnectorStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-SaveAsync>d_3.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Dialogs\BotData.cs:line 211 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<Save>d_10.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Dialogs\BotData.cs:line 421 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-FlushAsync>d_5.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Dialogs\BotData.cs:line 281 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.BotDataBase1.<FlushAsync>d__9.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Dialogs\BotData.cs:line 456 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__61.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Dialogs\DialogTask.cs:line 413 --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUserTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__51.MoveNext() in C:\Projects\GitHub\BotBuilder-NuGet3.1.0\CSharp\Library\Dialogs\DialogTask.cs:line 437
    [BotAuthentication]
    public class ActivityController : ApiController
    {
        private readonly List<string> _supportedActivityTypes = new List<string>
        {
            ActivityTypes.Message,
            ActivityTypes.ContactRelationUpdate,
            ActivityTypes.ConversationUpdate,
            ActivityTypes.Typing
        };

        [HttpPost]
        [Route("Api/Activities")]
        public async Task<IHttpActionResult> ReceiveAsync(
            [FromBody] Activity activity)
        {
            if (_supportedActivityTypes.Contains(activity.Type))
            {
                await Conversation.SendAsync(activity, () => new BotDialog());
            }

            return StatusCode(HttpStatusCode.Accepted);
        }
    }

    [Serializable]
    public class BotDialog : IDialog
    {
        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(ActivityReceivedAsync);
        }

        public async Task ActivityReceivedAsync(IDialogContext context, IAwaitable<IActivity> argument)
        {
            IActivity activity = await argument;

            switch (activity.Type)
            {
                case ActivityTypes.Message:
                    await MessageReceivedAsync(context, (IMessageActivity) activity);
                    break;
                case ActivityTypes.ContactRelationUpdate:
                    await ConversationUpdateReceivedAsync(context, (IConversationUpdateActivity) activity);
                    break;
                case ActivityTypes.ConversationUpdate:
                    await ContactRelationUpdateReceivedAsync(context, (IContactRelationUpdateActivity) activity);
                    break;
                case ActivityTypes.Typing:
                    await TypingReceivedAsync(context, (ITypingActivity)activity);
                    break;
            }
        }

        public async Task MessageReceivedAsync(IDialogContext context, IMessageActivity argument)
        {
            await context.PostAsync(string.Format("Message Received: {0}", argument.Text));
            context.Wait(ActivityReceivedAsync);
        }

        public async Task ConversationUpdateReceivedAsync(
            IDialogContext context, IConversationUpdateActivity argument)
        {
            await context.PostAsync("Conversation Update Received");
            context.Wait(ActivityReceivedAsync);
        }

        public async Task ContactRelationUpdateReceivedAsync(
            IDialogContext context, IContactRelationUpdateActivity argument)
        {
            await context.PostAsync("Contact Relation Update Received");
            context.Wait(ActivityReceivedAsync);
        }

        public async Task TypingReceivedAsync(
            IDialogContext context, ITypingActivity argument)
        {
            await context.PostAsync("Typing Received");
            context.Wait(ActivityReceivedAsync);
        }
    }

Closing comment (2016-08-11T18:47:17Z): @msft-shahins for visibility - this might be related to #960