-
Notifications
You must be signed in to change notification settings - Fork 251
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
Conversation
efb7b23
to
0c06c0e
Compare
9ab98a1
to
ec70199
Compare
ec70199
to
6a57894
Compare
@@ -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" |
There was a problem hiding this comment.
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
process.on('uncaughtException', async (reason, promise) => { | ||
for (const listener of listeners) { | ||
await listener.call(process, reason, promise) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) | |
} |
103df37
to
b72bcd5
Compare
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
Changeset
Testing