newrelic / node-newrelic

New Relic Node.js agent code base. Developers are welcome to create pull requests here, please see our contributing guidelines. For New Relic technical support, please go to http://support.newrelic.com.
Apache License 2.0
971 stars 399 forks source link

Warning: a promise was created in a handler shiim.js but was not returned from it #331

Closed nmargaritis closed 4 years ago

nmargaritis commented 4 years ago

Hello recently, we've added the newrelic package and we started seeing such messages for a specific endpoint. (express-sequalize-bluebird-newrelic etc) on our dev server (NODE_ENV=development)

Warning: a promise was created in a handler at /var/app/current/node_modules/newrelic/lib/shim/shim.js:1425:20 but was not returned from it, see http://goo.gl/rRqMUw at Function.Promise.attempt.Promise.try (/var/app/current/node_modules/bluebird/js/release/method.js:29:9)

Could you please provide an explanation for this issue (it is reported due to bluebird showing warnings on dev env)

I have created a minimal example to show how the functions that are executed look like.

// controller function
getAll(req, res, next) {
        this.modelHelper
            .findAll({
                x: req.params.x,
                y: req.params.y,
                z: req.query.z
            })
            .then(records => res.json({ results: records }))
            .catch(next);
    }

// different file
// model.findAll (sequalize)

    findAll(query) {
        ........ // some query parsing (no return statements)
        return model
            .findAll({
                where: // whereClause
            })
            .then(items => {
               // results parsing (no return statements)
                return _.values(result);
            });
    }
nijotz commented 4 years ago

Hi, thank you for reporting this issue! I can look into this, but first can I get the version of the newrelic module that you are using?

nmargaritis commented 4 years ago

Hi, thank you for reporting this issue! I can look into this, but first can I get the version of the newrelic module that you are using?

Hey thanks for the quick reply. I was using the latest version (6.4.1) and I also tested this down to version 5.0.0. The warning was reproducible.

nijotz commented 4 years ago

Hmm, nothing immediately stands out. I'll have to take some time to look into this. I'm currently working on a feature, but I'll add it to our queue.

nmargaritis commented 4 years ago

Hmm, nothing immediately stands out. I'll have to take some time to look into this. I'm currently working on a feature, but I'll add it to our queue.

Hey there, I spent some time to debug this and it appears that you are simply just a propagator of the warning due to the way the module is operating. The warning originates from the sequalize module and does appear with and without your package. The only thing changing when your package is installed is the stack trace. The stack trace caused me to open this issue here and not in sequalize but it was not an issue of newrelic all along.

I am closing this issue.

I cite (found in this issue)

There are still some code segment in Sequelize code base that don't catch or return promise. We are actively working on finding and fixing those sections. Until then you will have to use the suggested environment variables to turn off the warnings. So its our fault not Bluebird's :)

nijotz commented 4 years ago

Thanks for investigating and updating the ticket! Hopefully if others run into this issue, they'll find this information useful