Getting intermittent 502 (Bad Gateway) error with https://directline.botframework.com API in bot ...
Hi All,
I am getting 502 Bad Gateway error some time when i tried to call DirectLine API to send the Activity to BOT. Even we have also implement custom bot state. Is there anything else we have to implement with our bot.
Here i have putt the exception which i get from log and this log is generating at below line:
Code Snnipet:
using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://directline.botframework.com"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", BotSecret);
string url = $"**/v3/directline/conversations/{convId}/activities?watermark={currentWaterMark}";**
Activity userObj = new Activity()
{
text = userText,
type = "message",
from = new From
{
id = eid,
name = eid
}
};
StringContent strContent = new StringContent(JsonConvert.SerializeObject(userObj), Encoding.UTF8, "application/json");
**using (var response = await client.PostAsync(url, strContent).ConfigureAwait(false))-----here i am getting 502 error**
{
if (response.IsSuccessStatusCode)
{
}
}
}
Exception Details:
{
"StartTime":"2019-02-11 13:39:05.5442",
"Message":{
"ThreadId":"16",
"Level":"ERROR",
"Message":"Response status code does not indicate success: 502 (Bad Gateway).",
"Elapsed Time":"21945.0597"
},
"Conversation":{
"ConversationId":"New Conversation Id: ",
"EnterpriseId":"sip:",
"Input":"Hey",
"Parameter":"Response: StatusCode: 502, ReasonPhrase: 'Bad Gateway', Version: 1.1, Content: System.Net.Http.StreamContent,
Headers:\r\n{\r\n Pragma: no-cache\r\n Strict-Transport-Security: max-age=31536000\r\n
Cache-Control: no-cache\r\n Date: Mon, 11 Feb 2019 13:39:04 GMT\r\n Server: Microsoft-IIS/10.0\r\n*
Content-Length: 131\r\n Content-Type: application/json; charset=utf-8\r\n Expires: -1\r\n}"
},
"Exception":{
"Exception Message":"Response status code does not indicate success: 502 (Bad Gateway).",
"Call Stack":" at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()\r\n
at XXXXXXXXXXXXXXXXXd__30.MoveNext()
in D:\a\1\s\XXXXXXXXXXXXXX.cs:line 643"
}
}
Hi @Rashree138
This looks the same as this issue: https://github.com/Microsoft/BotFramework-Services/issues/39#issuecomment-463321808
Please follow along there for updates.
Hi Eric Dahlvang,
in case our issue we have already using TLS1.2 and other recommended setting. BUt still we are getting the error. so please let me what should be the changes we need to do....
Below line is raising the issue:
<<<<<using (var response = await client.PostAsync(url, strContent).ConfigureAwait(false))>>>>>.
update TLS also in code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 ;
Thanks, Raj
Hi @Rashree138
There are a couple different problems:
- Errors from internal dependencies a. We are in the process of moving our internal databases to CosmosDB which will give better performance and resiliency. That should be done in the next couple weeks.
- Errors from the platform a. We've battling a networking problem and have engaged other Azure teams to root cause this. This is our highest priority issue.
- Errors from deployment a. We are deploying some fixes that will make deployments less impactful. This should also be in place in the next couple weeks
The good news is that we're aware of each of these and making progress on their fixes. The bad news is that it's taking far too long and for that I apologize. These issues are frustrating for us, too.
Please follow this issue for updates: https://github.com/Microsoft/BotFramework-Services/issues/39#issuecomment-463321808