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.

Process not exiting?

See original GitHub issue

Hi,

I’m trying to use bookshelf.js to populate my database via a nodejs script (executed in a cronjob). However I noticed that the process doesn’t exit even after the records are successfully written to the database. Is there something I’m supposed to do to make it exit?

I’ve tried the following simple code and it doesn’t exit either:

var knex = require('knex')({
  client: 'postgresql',
  connection: {
    host     : '127.0.0.1',
    user     : 'npow',
    password : '',
    database : 'miserly',
    charset  : 'utf8'
  }
});

var bookshelf = require('bookshelf')(knex);
console.log('here');

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
johanneslumpecommented, Jul 1, 2014

How about something along these lines:

var num = 5;
var saves = [];

for (var i = 0; i < num; ++i) {
    saves.push(Store.forge({ ... }).save());
}

Promise.all(saves)
.then(function () {
    return knex.destroy();
})
.then(function () {
    console.log('all done');
});
5reactions
tgriessercommented, Jul 1, 2014

Yeah, @carldanley just brought this up to me tonight as well, I guess this might be a good FAQ add.

But yeah, calling knex.destroy(cb) should do it. Or process.exit which isn’t as graceful but gets the job done.

The way to think about it is that opening pooled database connections is kind of like opening a new http server with .createServer… it won’t exit until you tell it to, so you should just tell it to explicitly when your script is finished.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is process not exiting and how to get it to exit
I'm using a pipe in order to let these run concurrently, and brackets to group the commands such that sleep occurs first (the...
Read more >
Child Process not exiting in Piping [duplicate] - Stack Overflow
If you leave the line commented, wc command is only terminating because the parent exits and all of its file descriptors get closed....
Read more >
Process not closing in Task Manager on Windows 11? Fix it now
Snap! Process not closing in Task Manager? Fix it now!Easy peasy, this video will guide you on the best solutions!
Read more >
Issue 35122: Process not exiting on unhandled exception ...
I have attached a simple reproducer. When main() raises the unhandled exception, the process does not exit. However, if the size of data...
Read more >
Ghostscript process does not exit - Google Groups
Ghostscript process does not exit. 656 views. Skip to first unread message ... until I manually kill the gs.exe process using Windows Task...
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