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

capture uncaught exceptions in aws-lambda #1900

Merged
merged 9 commits into from
Mar 1, 2023

Conversation

djskinner
Copy link
Contributor

@djskinner djskinner commented Jan 11, 2023

Goal

AWS add a default unhandledRejection listener that forcefully exits the process. To workaround this the aws-lambda plugin removes all the listeners and only runs them after our own unhandled rejection handler has run.

It turns out the same thing is happening with uncaught exceptions but we weren't handling that case. This PR adds support for uncaught exceptions in the same manner as unhandled rejections.

To be clear the aws-lambda plugin previously was not reporting any errors that were caught by node's global uncaught exception handler. This PR fixes that.

Design

  • Same approach as used for unhandled rejections

Changeset

Testing

  • e2e test was added covering this case
  • Verified locally using aws sam

@github-actions
Copy link

github-actions bot commented Jan 11, 2023

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 44.63 kB 13.64 kB
After 44.63 kB 13.64 kB
± No change No change

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against eda4675

@djskinner djskinner force-pushed the node-remove-domain-3 branch 2 times, most recently from 9ab98a1 to ec70199 Compare January 23, 2023 14:40
@djskinner djskinner changed the base branch from node-remove-domain-2 to node-remove-domain January 23, 2023 17:02
@@ -91,13 +117,12 @@ Scenario Outline: unhandled exceptions are reported when using serverless-expres
Scenario: unhandled asynchronous exceptions are reported when using serverless-express
Given I setup the environment
When I invoke the "ExpressFunction" lambda in "features/fixtures/serverless-express-app" with the "events/unhandled-async.json" event
Then the lambda response "errorMessage" equals "busted"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The domain error handler was (incorrectly) preventing the application from crashing and returning a response. Now, the exception goes to the top-level uncaught exception handler before the process exists as it should

@djskinner djskinner marked this pull request as ready for review January 23, 2023 17:04
Comment on lines 48 to 51
process.on('uncaughtException', async (reason, promise) => {
for (const listener of listeners) {
await listener.call(process, reason, promise)
}
Copy link
Contributor

@imjoehaines imjoehaines Jan 30, 2023

Choose a reason for hiding this comment

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

Suggested change
process.on('uncaughtException', async (reason, promise) => {
for (const listener of listeners) {
await listener.call(process, reason, promise)
}
process.on('uncaughtException', async (err, origin) => {
for (const listener of listeners) {
await listener.call(process, err, origin)
}

@djskinner djskinner force-pushed the node-remove-domain branch 5 times, most recently from 103df37 to b72bcd5 Compare February 23, 2023 14:15
@djskinner djskinner merged commit 054ea19 into node-remove-domain Mar 1, 2023
@djskinner djskinner deleted the node-remove-domain-3 branch March 1, 2023 17:12
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