Skip to content

Commit 7a1118e

Browse files
committed
improvement: add listener for uncaughtException
This makes sure that uncaught exceptions are logged before the process quits.
1 parent ddfa4fa commit 7a1118e

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

dataserver.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ const arsenal = require('arsenal');
44
const { config } = require('./lib/Config.js');
55
const logger = require('./lib/utilities/logger');
66

7+
process.on('uncaughtException', err => {
8+
logger.fatal('caught error', {
9+
error: err.message,
10+
stack: err.stack,
11+
workerId: this.worker ? this.worker.id : undefined,
12+
workerPid: this.worker ? this.worker.process.pid : undefined,
13+
});
14+
process.exit(1);
15+
});
16+
717
if (config.backends.data === 'file' ||
818
(config.backends.data === 'multiple' &&
919
config.backends.metadata !== 'scality')) {

mdserver.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
const { config } = require('./lib/Config.js');
44
const MetadataFileServer =
55
require('arsenal').storage.metadata.MetadataFileServer;
6+
const logger = require('./lib/utilities/logger');
7+
8+
process.on('uncaughtException', err => {
9+
logger.fatal('caught error', {
10+
error: err.message,
11+
stack: err.stack,
12+
workerId: this.worker ? this.worker.id : undefined,
13+
workerPid: this.worker ? this.worker.process.pid : undefined,
14+
});
15+
process.exit(1);
16+
});
617

718
if (config.backends.metadata === 'file') {
819
const mdServer = new MetadataFileServer(

0 commit comments

Comments
 (0)