Bluebird unusable in AWS Lambda / NodeJS
See original GitHub issue-
What version of bluebird is the issue happening on? 3.4.7
-
What platform and version? (For example Node.js 0.12 or Google Chrome 32) NodeJS 4.3
-
Did this issue happen with earlier version of bluebird? Unknown
In an AWS Lambda function written in JS, using bluebird and executing on NodeJS:
- a promise is created
- on a setTimeout, the promise is resolved
- when it’s resolved, the lambda function callback is invoked
IF the lambda function’s execution timeout occurs before the setTimeout, the internal state of the bluebird library is hosed, and not only does this invocation of the lambda function time out, but ALL FURTHER invocations of the lambda function fail by timing out.
Code below (sans node_modules needed for packaging as lambda fn). Note that the code below uses the input event’s .timeout
property for the setTimeout
.
var Promise = require("bluebird");
module.exports.hello = function(event, context, cb) {
var p = new Promise(function(resolve, reject) {
setTimeout(
function() {
resolve();
},
event.timeout);
});
p.then(function(foo) {
cb(null, "cb happy");
});
};
Issue Analytics
- State:
- Created 7 years ago
- Comments:11
Top Results From Across the Web
Bluebird with Lambda not returning data - Stack Overflow
When your promise chain ends, the connection returns to the pool and WAITS to be used again, thus lambda timeouts since it's never...
Read more >Using JavaScript Promises - AWS Documentation
The AWS.Request.promise method provides a way to call a service operation and manage asynchronous flow instead of using callbacks. In Node.js and browser ......
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
js appear straight out unusable for whatever you are trying to achieve. In this article, we will take a look at ten common...
Read more >AWS Lambda - constant timeout when using bluebird Promise
js function (running on the Node.js 4.3 runtime), this symptom is similar to what one'd expect if a synchronous operation is blocking the...
Read more >Stacktraces on promises fairly useless : r/node - Reddit
Stacktraces on promises fairly useless. So coming from java and PHP, I am used to much ... AWS Lambda Now Has Support for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@truedat101 My bad, I isolated this issue on our code and turns out that this was related to ioredis, not Bluebird. The solution to prevent Lambda from timing out is at: https://www.linkedin.com/pulse/aws-lambda-reusable-resources-marjan-sterjev.
This is a WTF moment… No real problem with Bluebird… Seems to be an AWS/Lambda problem. Bumping up the RAM allocated to the lambda function makes everything better… Completely inexplicable. I’m opening up a ticket with AWS.