palmerabollo / botbuilder-aws-lambda

Helper to deploy your bot as a serverless function (AWS Lambda)
Apache License 2.0
9 stars 1 forks source link

AWS Lambda Timeout #1

Closed crisboarna closed 6 years ago

crisboarna commented 6 years ago

Hi, From what I can see, Bot Framework is immediately returning a {body:'',statusCode:202} to provide the user feedback that message was sent, which is the root cause of needing a library to circumvent that (hence why we here). Problem is that although it calls response.end(), it never seems to call the callback as lambda never shuts down and always times out. Additionally, due to not being able to send this message, user gets feedback that couldn't send retry although bot has already completed the dialog as expected. Could you please help me with this ?

palmerabollo commented 6 years ago

Hi @crisboarna , I'm not sure I understand what your issue is. Do you get those timeouts in the lambda function using botbuilder-aws-lambda? Can you share some code?

I've a bot running in a lambda function and it works fine. This module wraps the request and the response to call the lambda callback when the botbuilder ends the response, so the lambda ends, too.

crisboarna commented 6 years ago

Hi, Yes, I am giving as handler to AWS Lambda as such: lambda.js

const lambda = require('botbuilder-aws-lambda');
const connector = require('../service/');
const handler = lambda(connector);
module.exports= handler;

service/index.js

const connector = require('../config/');
const bot = new UniversalBot(connector...);
module.exports= connector;

config/index.js


const connector = new ChatConnector({
  appId: process.env.MICROSOFT_APP_ID,
  appPassword: process.env.MICROSOFT_APP_PASSWORD,
});

export default connector;

Looking on CloudWatch logs I can see that it calls the res.end() wrapper which is supposed to call the callback which should also give client a User at 12:00:00 PM under the message. I can see the payload is {body:'',statusCode:202} which would do this task, but it is never received. Additionally, this happens before the DynamoBotStorage returns and processes message so if it were to trigger callback it would not work at all ? Currently since the callback is not called, it does the processing without the 'Seen' notification to client, and lambda timeout due to time limit exceeded.

Given this behaviour I am uncertain how to proceed with it. Do you have any ideas what may be wrong ?

The lambda sends all the messages as expected in the meanwhile, so it functions in that regards at the very least.

palmerabollo commented 6 years ago

Yes, the code looks fine. It should work. I use botbuilder@3.8.1, which version are you using? I don't use DynamoBotStorage but I don't think those details are causing the issue.

crisboarna commented 6 years ago

@Issue was caused by usage of App Insights that has default setting to use batch delayed sending of telemetry data which kept the event loop busy causing the lambda timeout. Fixed it by adding

appInsights.setup()
...
.setUseDiskRetryCaching(false)
...
and
appInsightsInstance.config.maxBatchIntervalMs = 0;

and now it works.