Closed rliberoff closed 7 months ago
Maybe the question is – if there is no bug – how to correctly handle exceptions in the CloudAdapter
when using the ShowTypingMiddleware
.
Please advice.
Thank you.
Menawhile we created a custom middleware. It is actually a copy of yours, but with a slightly different FinishTypingTaskAsync
method, which is where we found the issue occurs.
private async Task FinishTypingTaskAsync(ITurnContext turnContext)
{
if (string.IsNullOrEmpty(turnContext?.Activity?.Conversation?.Id) && !tasks.ContainsKey(turnContext.Activity.Conversation.Id))
{
return;
}
// Cancel the typing loop.
tasks.TryGetValue(turnContext.Activity.Conversation.Id, out var item);
var (typingTask, cts) = item;
cts?.Cancel();
cts?.Dispose();
if (typingTask != null)
{
if (typingTask.Exception == null)
{
await typingTask.ConfigureAwait(false);
}
typingTask.Dispose();
}
tasks.TryRemove(turnContext.Activity.Conversation.Id, out _);
}
Please notice the if (typingTask.Exception == null)
which detects if there is an exception in the (previous) task.
Thank you.
Hi @rliberoff, We were able to reproduce the issue by forcing an error in the OnMessageActivityAsync method and another one in the OnTurnError. We'll analyze how the correct behavior should be.
Hi @JhontSouth!
Thank you. If there’s anything more I can assist you with, please don’t hesitate to reach out.
Merged in https://github.com/microsoft/botbuilder-dotnet/pull/6772. Available next release.
Version
I'm using 4.22.2
Describe the bug
When using the
ShowTypingMiddleware
in aCloudAdapter
, it thows anSystem.ObjectDisposedException
with messageCannot access a disposed object. Object name: 'Get'.
after an exception has been handled by theOnTurnError
error handler.This is the stack trace:
To Reproduce
Just create the simplest bot possible and
Use
theShowTypingMiddleware
. Produce an exception to be capture and handled by theCloudAdapter
with theOnTurnError
handler. Then throw a second exception and you will get this error.Expected behavior
This middleware should show a typing indicator in Microsoft Teams and also in a web chat without throwing exceptions.
Screenshots
N/A
Additional context
N/A