Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise keep node process from exit #626

Closed
vothanhkiet opened this Issue May 22, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@vothanhkiet
Copy link

vothanhkiet commented May 22, 2015

I write a tool for migrating data using Bluebird promise, so that user can trigger this tool directly via node command. Example:

node migrate.js

The problem is, node process will not exist after complete all operation. Here is the content of main migrate.js, the exec() function return a promise.

var migrate = require('../elasticsearch/migrate');
var setting = require('../../config/setting');

var cmd = new migrate(setting.NewConfig.search, true);
cmd.exec()
    .then(function () {
        console.info('Operation completed');
        //process.exit(0);
    })
    .catch(function (err) {
        console.error(err);
        //process.exit(1);
    });

At the moment I must trigger process.exit() to kill the process.

@petkaantonov

This comment has been minimized.

Copy link
Owner

petkaantonov commented May 22, 2015

Promise doesn't keep process alive, it is some other api that you are using. Try checking process._getActiveRequests() and process._getActiveHandles() to see what is keeping the process alive.

@vothanhkiet

This comment has been minimized.

Copy link
Author

vothanhkiet commented May 22, 2015

Thank for you support, after rechecking current open handles via process._getActiveHandles(), the process was kept from exiting because of Knex library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.