Skip to content

Make registerCrashHandler easier to use in AWS Lambdas #1647

@gallal

Description

@gallal

Lambdas can be called multiple times in the same container. Calling registerCrashHandler multiple times is the same process throws an error with the message: Crash Handler cannot be used alongside other uncaughtException or unhandledRejection handlers.

What problem does this feature solve?

  • It is frustrating to see these errors in production but not during development because Serverless Offline does not reuse containers by default
  • It should not be necessary to do this in code:
const existingListeners = [
	...process.listeners('uncaughtException'), 
	...process.listeners('unhandledRejection')
];
if (!existingListeners.length {
	registerCrashHandler();
}

Ideal solution

I am not sure, but maybe one of:

  • Defaulting to allowing multiple registrations? Maybe when running in a Lambda only?
  • Allowing users to specify that they know it is safe to register multiple times via an option. This won't solve the first issue, though.

Alternatives

Update docs to make it clear that we need to do something different in AWS Lambdas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions