Skip to content

Commit

Permalink
Merge pull request #290 from pelias/local_worker_premature_shutdown
Browse files Browse the repository at this point in the history
gracefully handle shutting down workers before the service has finished instantiating
  • Loading branch information
missinglink authored Mar 18, 2020
2 parents b7c61a6 + 828fb2f commit d25718e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/localPipResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const logger = require('pelias-logger').get('wof-admin-lookup');
const createPipService = require('./pip/index').create;
const killAllWorkers = require('./pip/index').killAllWorkers;
const _ = require('lodash');

/**
Expand All @@ -19,7 +20,6 @@ function LocalPipService(datapath, layers) {
}
self.pipService = service;
});

}

/**
Expand Down Expand Up @@ -76,6 +76,13 @@ LocalPipService.prototype.end = function end() {
if (this.pipService) {
logger.info('Shutting down admin lookup service');
this.pipService.end();
} else {
/**
* this is required to handle the case where the '$this.pipService'
* variable is not available yet but the stream has ended and needs to
* terminate all workers, such as when the stream input is /dev/null.
*/
killAllWorkers();
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/pip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* functions for initializing them and searching them.
*/

'use strict';

const path = require('path');
const childProcess = require( 'child_process' );
const logger = require( 'pelias-logger' ).get( 'wof-pip-service:master' );
Expand Down Expand Up @@ -134,6 +132,7 @@ module.exports.create = function createPIPService(datapath, layers, localizedAdm
function killAllWorkers() {
_.values(workers).forEach(worker => worker.kill());
}
module.exports.killAllWorkers = killAllWorkers;

function startWorker(datapath, layer, localizedAdminNames, callback) {
const worker = childProcess.fork(path.join(__dirname, 'worker'), [layer, datapath, localizedAdminNames]);
Expand Down

0 comments on commit d25718e

Please sign in to comment.