()
| 205 | |
| 206 | let gracefullyClosing = false; |
| 207 | async function gracefullyClose(): Promise<void> { |
| 208 | // We keep listeners until we are done, to handle 'exit' and 'SIGINT' while |
| 209 | // asynchronously closing to prevent zombie processes. This might introduce |
| 210 | // reentrancy to this function, for example user sends SIGINT second time. |
| 211 | // In this case, let's forcefully kill the process. |
| 212 | if (gracefullyClosing) { |
| 213 | options.log(`[pid=${spawnedProcess.pid}] <forcefully close>`); |
| 214 | killProcess(); |
| 215 | await waitForCleanup; // Ensure the process is dead and we have cleaned up. |
| 216 | return; |
| 217 | } |
| 218 | gracefullyClosing = true; |
| 219 | options.log(`[pid=${spawnedProcess.pid}] <gracefully close start>`); |
| 220 | await options.attemptToGracefullyClose().catch(() => killProcess()); |
| 221 | await waitForCleanup; // Ensure the process is dead and we have cleaned up. |
| 222 | options.log(`[pid=${spawnedProcess.pid}] <gracefully close end>`); |
| 223 | } |
| 224 | |
| 225 | // This method has to be sync to be used in the 'exit' event handler. |
| 226 | function killProcess() { |
no test coverage detected
searching dependent graphs…