jprichardson / node-death Goto Github PK
View Code? Open in Web Editor NEWGracefully cleanup when termination signals are sent to your process.
License: MIT License
Gracefully cleanup when termination signals are sent to your process.
License: MIT License
I've noticed that since death
handles SIGINT, node no longer exists when it receives SIGINT.
There's a bug in this code that prevents you from setting the option uncaughtException
to false.
defaultConfig.uncaughtException = arg.ue || arg.uncaught || arg.exception || true
This will always set the value to true, because the ||
(or) applies to both undefined
as well as false
.
A more explicit check is needed
if( arg.ue != null ){
defaultConfig.uncaughtException = arg.ue
}
(!=null will only let it go through if the value is not null or undefined)
It also doesn't actually check for the value of uncaughtException
, only the shorthand versions.
Hi Team,
Issue:
I'm using node-death in my project. Node-Death is working fine when I'm running my application in Windows platform. On 'SIGINT' (ctrl+c) its gracefully shutting down the open connections made in my application.
But when I issue 'SIGINT' signal from either MacOS or Linux platforms it, immediately shuts down the application without graceful shutdown of open connections. I have also used 'process.stdin.resume()' to prevent immediate shutdown, but still doesn't work.
Please find below my code:
import ON_DEATH from 'death';
import mongoose from './db.config';
import redisClient from './redis.config';
import { logger } from './pino.config';
const logError = (from, code, error) => {
logger.error({ from, code, error });
};
const logInfo = connectionName => (logger.info({ message: `Connection with ${connectionName} shutdown gracefully!!!` }));
const shutdownRedis = () => redisClient.quit();
const shutdownMongoose = () => mongoose.connection.close(false);
// Begin reading from stdin so the process does not exit.
process.stdin.resume();
const onDeathCallback = async () => {
try {
await shutdownRedis();
logInfo('Redis');
await shutdownMongoose();
logInfo('Mongo');
} catch (err) {
logError('death.config.onDeathCallback', 'ERR_GRACEFUL_CONN_SHUTDOWN', err);
}
};
ON_DEATH(onDeathCallback);
Expected Output:
Connection with Redis shutdown gracefully!!!
Connection with Mongo shutdown gracefully!!!
Actual Output:
No output as it doesn't execute the callback
Please kindly let me know if I'm doing anything wrong with the configurations.
Looking forward to your help/reply on the above issue.
Thanks & Regards,
Siddharth
The code on here has the ability to remove event listeners, but the npm hosted module has never been updated to include this. Would it be possible to update it?
$ node script.js | tee script.log
^Cevents.js:163
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at exports._errnoException (util.js:1050:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:814:14)
The script is:
var ON_DEATH = require('death'); //this is intentionally ugly
ON_DEATH(function(signal, err) { console.log('croak'); })
setTimeout(function () {}, 10000);
node-cleanup doesn't call my handler either, but at least doesn't display this ugly error message :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.