()
| 449 | let cleanupHandlersInstalled = false; |
| 450 | |
| 451 | function installGlobalCleanupHandlers() { |
| 452 | if (cleanupHandlersInstalled) return; |
| 453 | cleanupHandlersInstalled = true; |
| 454 | |
| 455 | const killAll = () => { |
| 456 | for (const [key, info] of PERSISTENT_SERVERS.entries()) { |
| 457 | try { |
| 458 | process.kill(info.pid, 'SIGTERM'); |
| 459 | } catch (err: any) { |
| 460 | debug(`Error sending SIGTERM to ${info.pid}: ${err}`); |
| 461 | } |
| 462 | try { |
| 463 | process.kill(info.pid, 'SIGKILL'); |
| 464 | } catch (err: any) { |
| 465 | debug(`Error sending SIGKILL to ${info.pid}: ${err}`); |
| 466 | } |
| 467 | PERSISTENT_SERVERS.delete(key); |
| 468 | } |
| 469 | if (restoreWarnings) { |
| 470 | try { |
| 471 | restoreWarnings(); |
| 472 | } catch (err: any) { |
| 473 | debug(`Error restoring warnings: ${err}`); |
| 474 | } |
| 475 | restoreWarnings = null; |
| 476 | } |
| 477 | }; |
| 478 | |
| 479 | // Do not exit on signals, so other interruption handlers |
| 480 | // can perform their cleanup routine. |
| 481 | process.on('SIGINT', () => { |
| 482 | killAll(); |
| 483 | }); |
| 484 | process.on('SIGTERM', () => { |
| 485 | killAll(); |
| 486 | }); |
| 487 | process.on('exit', () => { |
| 488 | killAll(); |
| 489 | }); |
| 490 | } |
| 491 | |
| 492 | interface DevShimResult { |
| 493 | module: string; |
no test coverage detected