The short version of my question: What, other than a timeout, can trigger a Node.js based AWS Lambda function to exit prior to the handler's callback function or context.success|done|fail being called?
The long (convoluted) version is: We've inherited an AWS Lambda function that we didn't write. We're seeing behavior on cold starts (the first invocation after a deploy) where the Lambda function will return a null response to API Gateway before the program has had a chance to invoke the handler's callback.
Also, during the second invocation of the function, we see the following error in our log.
[ERROR] [1626907621359] LAMBDA_RUNTIME Failed to post handler success response. Http response code: 400.
But this second response is processed normally and correctly.
A simplified version of the function looks like this
const otherCodeThatWrapsAbunchOfStuff = require('./other-code')
exports.handler = otherCodeThatWrapsAbunchOfStuff(
function handler (event, context, callback) {
callback(null, `Hello World`)
})
}
This otherCodeThatWrapsAbunchOfStuff returns a wrapped handler function, and also wraps the callback.
Using some local debugging our best reasoning about things right now is
- During a cold start, this code in
otherCodeThatWrapsAbunchOfStuffwe've inherited schedules the callback to be invoked via async means - [something happens] and the Lambda returns a
null - The Lambda freezes
- The next request comes in and the Lambda unfreezes
- The original callback fires, resulting in the
LAMBDA_RUNTIMEerror - The callback for the second invocation fires, resulting in a normal response
I realize you can't debug this program for me -- what I'm interesting in knowing is what sort of scenarios (other than a timeout -- we've bumped the Lambda timeout value and this "return null on cold start" behavior still happens and happens well before the timeout is reached) can cause an AWS Lambda function to "exit/respond early" without the callback being called.
process.exit()error : Error: Runtime exited without providing a reason. Runtime.ExitError