1"use strict"; 2// this spawns a child process that listens for SIGHUP when the 3// parent process exits, and after 200ms, sends a SIGKILL to the 4// child, in case it did not terminate. 5Object.defineProperty(exports, "__esModule", { value: true }); 6exports.watchdog = void 0; 7const child_process_1 = require("child_process"); 8const watchdogCode = String.raw ` 9const pid = parseInt(process.argv[1], 10) 10process.title = 'node (foreground-child watchdog pid=' + pid + ')' 11if (!isNaN(pid)) { 12 let barked = false 13 // keepalive 14 const interval = setInterval(() => {}, 60000) 15 const bark = () => { 16 clearInterval(interval) 17 if (barked) return 18 barked = true 19 process.removeListener('SIGHUP', bark) 20 setTimeout(() => { 21 try { 22 process.kill(pid, 'SIGKILL') 23 setTimeout(() => process.exit(), 200) 24 } catch (_) {} 25 }, 500) 26 }) 27 process.on('SIGHUP', bark) 28} 29`; 30const watchdog = (child) => { 31 let dogExited = false; 32 const dog = (0, child_process_1.spawn)(process.execPath, ['-e', watchdogCode, String(child.pid)], { 33 stdio: 'ignore', 34 }); 35 dog.on('exit', () => (dogExited = true)); 36 child.on('exit', () => { 37 if (!dogExited) 38 dog.kill('SIGTERM'); 39 }); 40 return dog; 41}; 42exports.watchdog = watchdog; 43//# sourceMappingURL=watchdog.js.map