botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

directline api 502 bad gateway

Open alexandruf opened this issue 7 years ago • 4 comments

Hi guys , direct line seems to have some problems today. I get 502 from time to time. errordirectline

I'm not sure if I have to open a ticket on azure directly. Can you please have a look?

alexandruf avatar Jan 22 '19 14:01 alexandruf

We are investigating this, and will get back to you shortly.

EricDahlvang avatar Jan 22 '19 21:01 EricDahlvang

The errors you've seen do not appear to be related to the Direct Line service.

Which version of Bot Builder is this bot using?

What is the bot using for state?

Is Application Insights configured for the bot and for the web application hosting the bot?

Bot: https://docs.microsoft.com/en-us/azure/bot-service/bot-service-manage-analytics?view=azure-bot-service-4.0#enable-analytics

Web Application: https://docs.microsoft.com/en-us/azure/application-insights/app-insights-asp-net

EricDahlvang avatar Jan 22 '19 22:01 EricDahlvang

Hi Eric! Thank you for looking into this!

I am using an old version of Bot Builder: 3.11.0 with connector on 3.11.1 For state, I use REDIS. Application Insights is not configured unfortunately.

I received 502 bad gateway intermittently from 14:00 UTC to approx. 15:00 UTC.

Usually, when this happens, there is a direct line issue and I follow this page (happened quite rarely lately).

Giving the fact that you state that errors are not related with Direct Line, let me ask you this:

What is your recommendation regarding dynamic port range? When you are making authenticated calls repeatedly to the same server (Direct Line), you are making and closing connections repeatedly. That connection stays in TIME_WAIT for 240 seconds by default.

Max dynamic port is 5000. So you get to use from 1024 to 5000 (approx. 4000 ports). This means 16 web service calls per second until you get a socket exception. It may be…my case (I am not sure .. dealing with async methods, I can see that exception only in visual studio if a check Common Language Runtime Exception ..maybe is another solution to this).

Anyway, what is your take on this? Should I raise the max range to 65534? Should I decrease the TIME_WAIT to a lower value? Whats the risk in doing so?

Alex

alexandruf avatar Jan 22 '19 22:01 alexandruf

The port exhaustion issues in BotBuilder V3 have be resolved in BotBuilder V4 by ensuring HttpClients are static. You should be able to write your Redis state store implementation to use a static HttpClient as well.

I'm not sure what to recommend for TIME_WAIT or port ranges. Making these changes is only a stop-gap solution anyway, pushing off the real issue. There are workarounds for V3 sdk port exhaustion such as: https://github.com/Microsoft/BotBuilder/issues/4075#issuecomment-360724246 and https://github.com/Microsoft/BotBuilder/issues/4901 But, if your bot is receiving enough traffic that this issue is a problem in production, then I recommend upgrading your bot to use the V4 sdk (this is a long term solution).

EricDahlvang avatar Jan 25 '19 20:01 EricDahlvang