Milkncookiez Milkncookiez - 12 days ago 6
Node.js Question

Sails app doesn't lower

In a custom script, I'm lifting Sails, doing some stuff, then calling

.lower()
but the app doesn't stop. No error is returned either...

const Sails = require('sails')
, rc = require('rc');

function run() {
Sails.lift(rc('sails', {process: 'manual'}), (err, server)=> {
if (err) {
console.error(err);
}

// ... do some stuff

Sails.lower({}, (err)=> {
console.log('ERROR', err);
return true;
});
});
});
}


The app just continues running. No error is returned from
.lower()
and it doesn't have a callback result by default. I debugged in the
lower.js
file itself and turns out that that code isn't even reached...

I think the problem is that
lower()
returns a callback, but my script doesn't accept one, so how do I manage this case?

Answer

So, actually the app was getting lowered and all services (HTTP, socket, etc.) were shut down, but the process itself continued running. process.exit() was the solution. So, I first gracefully lower all services and then terminate the process:

      Sails.lower({}, (err) => {
        if (err) {
          log.error('An error occurred while shutting the server down.');
        }
        process.exit();
      });
Comments