question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bluebird unusable in AWS Lambda / NodeJS

See original GitHub issue
  1. What version of bluebird is the issue happening on? 3.4.7

  2. What platform and version? (For example Node.js 0.12 or Google Chrome 32) NodeJS 4.3

  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:

  1. a promise is created
  2. on a setTimeout, the promise is resolved
  3. 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:closed
  • Created 7 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
simoncpucommented, Nov 13, 2017

@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.

1reaction
cvillecsteelecommented, Feb 15, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found