Getting "Sorry, my bot code is having issue" when first time talking to the bot"
Bot Info
- SDK Platform: .NET
- SDK Version: 3.15.2.2
- Active Channels: Direct Line
- Deployment Environment: Azure Bot Service
Issue Description
This issue mostly happened at the first time when talking to the bot, the Chrome console logs give 502 bad gateway. When enabled the Application Insight for the bot. we see the following details:
Exception Properties
| Event time | 5/14/2018, 9:43:49 AM | |
|---|---|---|
| Message | POST to chatbot-int 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+ |
|
| SDK version | dotnet:2.4.0-32153 | |
| Operation Id | |zVYGTaz7NFk=.a8d5d07c_ | |
| Parent Id | |zVYGTaz7NFk=.a8d5d07c_ | |
| Client IP address | 0.0.0.0 | |
| Sample rate | 1 | |
| Device type | PC | |
| City | Hong Kong | |
| State or province | Central and Western District | |
| Country or region | Hong Kong | |
| Cloud role name | bc-directline-easia | |
| Cloud role instance | RD00155DB09F3B | |
| Telemetry type | exception | |
| Problem Id | System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+ |
|
| Assembly | Microsoft.Bot.ChannelConnector, Version=3.2.1.0, Culture=neutral, PublicKeyToken=null |
Custom Data: Activity ID Iqdhobn4vKL1c8UKELOrEg|0000001 Bot endpoint https://chatbot-int.azurewebsites.net/api/messages From ID 1526262221844 Correlation ID |zVYGTaz7NFk=.a8d5d07c_ Channel ID directline Response body { "message": "An error has occurred." } Recipient ID chatbot-int@KBBk6VBs9oI Bot ID chatbot-int Conversation ID Iqdhobn4vKL1c8UKELOrEg Status code InternalServerError Activity type message EventName Exception
Callstack Method
Microsoft.Bot.Schema.BotException
Microsoft.Bot.ChannelConnector.BotAPI+
Code Example
Reproduction Steps
1. 2. 3.
Expected Behavior
Expect to get the bot reply without seeing any error
Actual Results
Getting "Sorry, my bot code is having issue" when almost each first time talking to the bot"
Can you share your bot's code? Or a small project that reproduces the issue?
Hi Eric,
Thanks for your quick response. Unfortunately we don't have the code snippet to exactly reproduce the issue. I have emailed you with our concerns and proposal to investigate the issue
Thanks, Kevin
I've responded to your email with the following:
“Sorry, my bot code is having an issue” is the generic message sent from the sdk to the bot user when an unexpected exception occurs. There are a few ways to get more information about the exception:
- Override the default PostUnhandledExceptionToUser implementation:
The default PostUnhandledExceptionToUser can be found here: https://github.com/Microsoft/BotBuilder/blob/2162e4018914b77628e40f2998651486772d7825/CSharp/Library/Microsoft.Bot.Builder/ConnectorEx/PostToBot.cs#L137
To override it, add this AutoFac registration to Global.asax.cs:
Conversation.UpdateContainer(
builder =>
{
builder
.RegisterType<CustomPostUnhandledExceptionToUser>()
.Keyed<IPostToBot>(typeof(PostUnhandledExceptionToUser));
});
Using this class:
public sealed class CustomPostUnhandledExceptionToUser : IPostToBot
{
private readonly IPostToBot inner;
private readonly IBotToUser botToUser;
private readonly ResourceManager resources;
private readonly TraceListener trace;
public PostUnhandledExceptionToUser(IPostToBot inner, IBotToUser botToUser, ResourceManager resources, TraceListener trace)
{
SetField.NotNull(out this.inner, nameof(inner), inner);
SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser);
SetField.NotNull(out this.resources, nameof(resources), resources);
SetField.NotNull(out this.trace, nameof(trace), trace);
}
async Task IPostToBot.PostAsync(IActivity activity, CancellationToken token)
{
try
{
await this.inner.PostAsync(activity, token);
}
catch (Exception ex)
{
try
{
//LOG the Exception here
//comment this line to not send a custom message to the user
await this.botToUser.PostAsync("Custom message to user on error");
}
catch (Exception inner)
{
this.trace.WriteLine(inner);
}
throw;
}
}
}
- Similar to the above method, you can create a LogIfExceptionDialog and chain it to the end of the dialog stack in the MessagesController:
public static class ExceptionLogging
{
public static IDialog<T> LogIfException<T, E>(this IDialog<T> antecedent) where E : Exception
{
return new LogIfExceptionDialog<T, E>(antecedent);
}
public static IDialog<T> LogIfException<T>(this IDialog<T> antecedent)
{
return new LogIfExceptionDialog<T, Exception>(antecedent);
}
}
[Serializable]
public class LogIfExceptionDialog<T, E> : IDialog<T> where E : Exception
{
public readonly IDialog<T> Antecedent;
public LogIfExceptionDialog(IDialog<T> antecedent)
{
SetField.NotNull(out this.Antecedent, nameof(antecedent), antecedent);
}
async Task IDialog<T>.StartAsync(IDialogContext context)
{
context.Call<T>(this.Antecedent, ResumeAsync);
}
private async Task ResumeAsync(IDialogContext context, IAwaitable<T> result)
{
try
{
context.Done(await result);
}
catch (E exception)
{
//log exception (with stack trace, and end the dialog)
context.Done(default(T));
}
}
}
In the messages controller:
await Conversation.SendAsync(activity, () => new RootDialog().LogIfException());
We have exactly the same problem, even if you use the core-multiDialogs example, from BotBuilder-Samples.....
after a few hours the problem occurs, the next message goes to the bot without any problems.
Same problem here
@kevinport @bodyzatva Are you still having this issue with the latest sdk (3.15.3)? https://www.nuget.org/packages/Microsoft.Bot.Builder/
@kevinport i will check tomorrow and give feedback
Has anyone found a solution to this issue?
@EricDahlvang @bodyzatva We are still in the test phase. Since the error only ever occurs every few hours or days. We can't be sure if the bug is fixed after a few days.
It turned out to be a proxy issue. Call to botframework sites were blocked by internal proxy. Whitelisting domain worked.
On Fri, Jul 13, 2018 at 2:34 AM Kevin Port [email protected] wrote:
@EricDahlvang https://github.com/EricDahlvang @bodyzatva https://github.com/bodyzatva We are still in the test phase. Since the error only ever occurs every few hours or days. We can't be sure if the bug is fixed after a few days.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/4603#issuecomment-404740234, or mute the thread https://github.com/notifications/unsubscribe-auth/AbWhNvw4wctJdVWE4oATftgLQ9RtBEXsks5uGD-JgaJpZM4T9Y_7 .
-- Thanks, Jignesh Patel
@jignesh84 where did you the whitelisting? azure or sourcecode ?
It was on infrastructure side.
On Fri, Jul 13, 2018 at 8:43 AM Kevin Port [email protected] wrote:
@jignesh84 https://github.com/jignesh84 where did you the whitelisting? azure or sourcecode ?
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/4603#issuecomment-404822457, or mute the thread https://github.com/notifications/unsubscribe-auth/AbWhNoTRpo5MVFNNyU9rbECCayoS9BNAks5uGJXogaJpZM4T9Y_7 .
-- Thanks, Jignesh Patel
@jignesh84 you are not hosting on azure?
No aws
On Sat, Jul 14, 2018 at 9:01 AM Kevin Port [email protected] wrote:
@jignesh84 https://github.com/jignesh84 you are not hosting on azure?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/4603#issuecomment-405022364, or mute the thread https://github.com/notifications/unsubscribe-auth/AbWhNj3AYNl27Ny9Clnvv6mk2Vpl6kFAks5uGeusgaJpZM4T9Y_7 .
-- Thanks, Jignesh Patel
that means that the azure services block themselves or other internal botframwork calls.
@jignesh84 So you haven't noticed any more problems?
That depends, in my environment everything goes through proxy so we would have to explicitly whitelist hosts. If you have private cloud and all outbound calls are going through proxy then you need check for those. I would issue a curl from host to see if it is blocked by anything.
On Sat, Jul 14, 2018 at 9:16 AM Kevin Port [email protected] wrote:
that means that the azure services block themselves or other internal botframwork calls.
@ So you haven't noticed any more problems?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/4603#issuecomment-405023154, or mute the thread https://github.com/notifications/unsubscribe-auth/AbWhNoVc7QxJhVhCk1_NxOlyPDpaY5t6ks5uGe8XgaJpZM4T9Y_7 .
-- Thanks, Jignesh Patel
@kevinport are you on the latest sdk? 3.15.3
The team rolled back some code that was likely causing the issues you've been seeing: https://github.com/Microsoft/BotBuilder/pull/4810
Hello everyone. I'm having the same issue after a few hours or days that the bot stays in "stand by", like @kevinport said. I updated the sdk like you suggested @EricDahlvang, but unfortunately the issue persists. Somebody found any other solution for this issue?
Thank you, Cleiton Barbieri
Hello everyone. I found a solution for the issue that I was having and that maybe can be useful for someone. After many searchs on internet and even some github forums I found some suggestions to make a downgrade of the SDK. I was facing this issue using the SDK 3.15.3 and 3.15.2.2. After the downgrade to the SDK 3.13.1.0, until today (8/13/2018) I didn't have more problems. I hope it helps.
My regards. Thank you. Cleiton Barbieri