add handler for SIGUSR1 to start drying up calls, useful as a generic mechanism on non-AWS deployments (#1482)

This commit is contained in:
Dave Horton
2025-12-30 13:31:42 -05:00
committed by GitHub
parent 3bd1dd6323
commit fdce05fa40

View File

@@ -100,6 +100,39 @@ module.exports = (logger) => {
else if (K8S) { else if (K8S) {
lifecycleEmitter.scaleIn = () => process.exit(0); lifecycleEmitter.scaleIn = () => process.exit(0);
} }
else {
process.on('SIGUSR1', () => {
logger.info('received SIGUSR1: begin drying up calls for scale-in');
dryUpCalls = true;
const {srf} = require('../..');
const {writeSystemAlerts} = srf.locals;
if (writeSystemAlerts) {
const {SystemState, FEATURE_SERVER} = require('./constants');
writeSystemAlerts({
system_component: FEATURE_SERVER,
state : SystemState.GracefulShutdownInProgress,
fields : {
detail: `feature-server with process_id ${process.pid} shutdown in progress`,
host: srf.locals?.ipv4
}
});
}
pingProxies(srf);
// if we have zero calls, we can complete the scale-in right
setTimeout(() => {
const calls = srf.locals.sessionTracker.count;
if (calls === 0) {
logger.info('scale-in can complete immediately as we have no calls in progress');
process.exit(0);
}
else {
logger.info(`${calls} calls in progress; scale-in will complete when they are done`);
}
}, 5000);
});
}
async function pingProxies(srf) { async function pingProxies(srf) {