Commit 1d0c889
fix(core): ensure postTasksExecution fires on SIGINT for continuous tasks (#34876)
## Current Behavior
When pressing Ctrl+C on continuous tasks, `postTasksExecution` never
fires because `process.exit()` in `running-tasks.ts` SIGINT handlers
kills the process before the orchestrator can run async cleanup and
lifecycle hooks.
## Expected Behavior
`postTasksExecution` fires reliably on Ctrl+C with complete task
results, without causing stale `RunningTasksService` DB entries that
block subsequent `nx` invocations with "Waiting for ... in another nx
process" messages.
## Technical Details
Re-applies #34623 (reverted in #34869) with fixes for the issues that
caused CI failures.
**Root cause of the revert**: Removing `process.exit()` from SIGINT
handlers left the nx process alive during async cleanup. The
`running_tasks` DB entry persisted with a still-alive PID, so new nx
processes saw it as a running task and hung.
**Fix 1 — Early DB cleanup**: Synchronously remove all owned DB entries
in the SIGINT handler *before* starting async cleanup. This replicates
the cleanup that `process.exit()` + Rust `Drop` previously provided —
from any external observer's perspective, the tasks are gone
immediately.
**Fix 2 — Always register onExit in startContinuousTask**: The original
PR added a guard that skipped `onExit` registration for initiating
tasks, assuming `executeNextBatchOfTasksUsingTaskSchedule` would handle
it. But `runContinuousTasks()` (used by DTE agents and Playwright) calls
`startContinuousTask` directly without going through `run()`. The
missing handler meant task exit was never processed — no DB cleanup, no
lifecycle hooks. This caused verdaccio (local-registry) to become
unreachable on DTE agents. The fix always registers `onExit` in
`startContinuousTask` and simplifies the
`executeNextBatchOfTasksUsingTaskSchedule` handler to only unblock the
thread.
Changes:
- Remove `process.exit()` from `running-tasks.ts` SIGINT handlers (lets
orchestrator run)
- Replace `cleanupDone` boolean with `cleanupPromise` (fixes
SIGINT/SIGTERM race)
- Set `stopRequested = true` for SIGTERM/SIGHUP (correct task
classification)
- Early synchronous DB cleanup in non-TUI SIGINT handler
- Always register `onExit` handler in `startContinuousTask` for both
initiating and non-initiating tasks
- Simplify initiating task handler in
`executeNextBatchOfTasksUsingTaskSchedule` to only call `res()`1 parent 31cc85e commit 1d0c889
File tree
2 files changed
+79
-51
lines changed- packages/nx/src
- executors/run-commands
- tasks-runner
2 files changed
+79
-51
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
528 | | - | |
529 | | - | |
530 | 528 | | |
531 | 529 | | |
532 | 530 | | |
| |||
710 | 708 | | |
711 | 709 | | |
712 | 710 | | |
713 | | - | |
714 | | - | |
715 | 711 | | |
716 | 712 | | |
717 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
232 | 233 | | |
233 | 234 | | |
234 | 235 | | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
| 236 | + | |
245 | 237 | | |
246 | 238 | | |
247 | 239 | | |
| |||
944 | 936 | | |
945 | 937 | | |
946 | 938 | | |
947 | | - | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
948 | 948 | | |
949 | 949 | | |
950 | 950 | | |
| |||
997 | 997 | | |
998 | 998 | | |
999 | 999 | | |
1000 | | - | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
1001 | 1009 | | |
1002 | 1010 | | |
1003 | 1011 | | |
| |||
1259 | 1267 | | |
1260 | 1268 | | |
1261 | 1269 | | |
1262 | | - | |
1263 | | - | |
| 1270 | + | |
| 1271 | + | |
1264 | 1272 | | |
1265 | 1273 | | |
1266 | 1274 | | |
1267 | 1275 | | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
1273 | 1280 | | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
1298 | 1304 | | |
1299 | 1305 | | |
1300 | 1306 | | |
| |||
1330 | 1336 | | |
1331 | 1337 | | |
1332 | 1338 | | |
1333 | | - | |
1334 | | - | |
| 1339 | + | |
| 1340 | + | |
1335 | 1341 | | |
1336 | | - | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
1337 | 1345 | | |
| 1346 | + | |
1338 | 1347 | | |
1339 | 1348 | | |
1340 | 1349 | | |
| |||
1396 | 1405 | | |
1397 | 1406 | | |
1398 | 1407 | | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
1399 | 1429 | | |
1400 | 1430 | | |
1401 | 1431 | | |
| |||
1405 | 1435 | | |
1406 | 1436 | | |
1407 | 1437 | | |
| 1438 | + | |
1408 | 1439 | | |
1409 | 1440 | | |
1410 | 1441 | | |
1411 | 1442 | | |
1412 | 1443 | | |
1413 | 1444 | | |
1414 | 1445 | | |
| 1446 | + | |
1415 | 1447 | | |
1416 | 1448 | | |
1417 | 1449 | | |
| |||
0 commit comments