Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions wrappers/wrapAsAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
* @returns {function(event, context): Promise} An async Lambda handler
*/
module.exports = function wrapAsAsync(handler) {
return async function(event, context) {
return async function(event, context, callback) {
// Support old runtimes that only accept callbacks and not async functions
if (callback != null){
return handler(event, context, callback)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Async wrapper resolves prematurely on old runtimes

High Severity

When an old Lambda runtime provides a callback, the callback != null branch does return handler(event, context, callback). Since the wrapped handlers (in cron.js, fanout.js, resource.js, test.js) are callback-style and return undefined synchronously, and the wrapper is async, the implicit Promise immediately resolves with undefined. The Lambda runtime uses this resolved Promise as the response, completing the invocation before the handler's actual work finishes and the callback is called. This causes all wrapped handlers to return undefined on Node.js 18–22 runtimes.

Fix in Cursor Fix in Web

return new Promise((resolve, reject) => {
handler(event, context, function(err, result) {
return handler(event, context, function(err, result) {
if (err) reject(err);
else resolve(result);
});
Expand Down
Loading