Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically notify when a lambda may timeout #1324

Merged
merged 4 commits into from
Mar 4, 2021

Conversation

imjoehaines
Copy link
Contributor

Goal

We can never be 100% sure that a timeout will happen because we need to notify with enough time for the event to be delivered. Therefore this is a best effort with a generous default value (1000ms) that errs on the side of delivering the warning at the cost of possible false positives. The default value can be changed by providing the new lambdaTimeoutNotifyMs parameter to createHandler, e.g.:

const bugsnagHandler = Bugsnag.getPlugin('awsLambda').createHandler({
  lambdaTimeoutNotifyMs: 500
})

If set to "0" we don't bother adding the warning at all. This is largely arbitrary as a value of 0 would never be triggered (because the lambda would timeout at the same time so we would never be able to deliver the event) but it allows users to turn this feature off if they don't want it

Testing

This can only be covered by unit tests because of a bug in AWS' SAM CLI: aws/aws-sam-cli#2519

In short, SAM returns a Unix timestamp from getRemainingTimeInMillis so the timeout could never be triggered with sam local invoke (short of mocking the function, which isn't really better than a unit test)

We can never be 100% sure that a timeout will happen because we need
to notify with enough time for the event to be delivered. Therefore
this is a best effort with a generous default value (1000ms) that
errs on the side of delivering the warning at the cost of possible
false positives

The default value can be changed by providing "lambdaTimeoutNotifyMs"
to createHandler. This is useful in cases where the lambda function
is very quick to execute and so can have a very short timeout without
necessarily being at risk of timing out

If set to "0" we don't bother adding the warning at all. This is
largely arbitrary as a value of 0 would never be triggered (because
the lambda would timeout at the same time)
@github-actions
Copy link

github-actions bot commented Mar 4, 2021

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 40.83 kB 12.60 kB
After 40.83 kB 12.60 kB
± No change No change

code coverage diff

Ok File Lines Branches Functions Statements
🔴 /home/runner/work/bugsnag-js/bugsnag-js/packages/plugin-aws-lambda/src/index.js 94.64%
(+1.46%)
94.29%
(-1.54%)
90.91%
(+0.91%)
94.64%
(+1.46%)
/home/runner/work/bugsnag-js/bugsnag-js/packages/plugin-aws-lambda/src/lambda-timeout-approaching.js 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)

Total:

Lines Branches Functions Statements
81.51%(+0.11%) 70.37%(+0.15%) 84.01%(+0.05%) 80.42%(+0.1%)

Generated by 🚫 dangerJS against d86cbf9

There's no point adding the timeout at all if it's too big as it
will never trigger
Copy link
Contributor

@bengourley bengourley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment inline.

This is already handled by the 'super' call
@imjoehaines imjoehaines merged commit fdf1583 into integration/aws-lambda Mar 4, 2021
@imjoehaines imjoehaines deleted the aws-lambda-timeout-warning branch March 4, 2021 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants