Repository navigation
Commit 872aba9
authored
fix(worker): terminate() reaches a worker still inside its entry script (#493)
* fix(worker): terminate() reaches a worker still inside its entry script
The worker's isolate was published to its wrapper only after the startup
function returned, i.e. after the entry script had finished evaluating, so
Terminate() found nothing to interrupt for a worker still in its entry: a
synchronous loop there ran forever, and a parked top-level await ended
only when the loader's settle deadline expired. Node and the web both
interrupt the running entry.
The isolate is now published right after the worker runtime is
initialized, before the entry runs, and the startup function honors a
terminate() that landed earlier by checking the flag before any app code.
A termination that lands inside the entry unwinds RunModule, which no
longer rethrows or reports on a terminating isolate, and the thread goes
straight to its existing teardown path. The module runner and the
exception constructor name a caught termination for what it is instead of
formatting the TryCatch, and the settle pump checks for one after its loop
too, so a termination is never reported as a timeout or as an entry
rejection.
Also documents the real resourceLimits and ios.priority Worker options in
docs/worker-threads.md, whose node:worker_threads table claimed the runtime
imposed no limits.
Suite 1735/0, also under AddressSanitizer.
Fixes #445
* fix(worker): keep a termination from being re-armed as an error on its way out
A termination that interrupts a CommonJS entry unwinds through the native
require callback, whose catch re-threw the message-only failure onto the
isolate as an ordinary Error: V8 then reported an exception rather than a
termination to RunModule's TryCatch, which built a full error report before
the worker boundary dropped it. ReThrowToV8 now leaves a terminating isolate
alone, since the pending termination is the failure, and RunModule consults
the same three termination signals as the settle pump.
The pumped graph walk ahead of an entry's compile bails on termination but
reports nothing, so LoadESModule went on to the synchronous HTTP loader, which
can block on the network. Both walks are now followed by a termination check.
Also refreshes the drain comment that described the pre-publication isolate
window, widens the startup-sweep spec's spread so its rounds reach the settle
pump, and corrects the resourceLimits RangeError wording.
* fix(worker): consult the termination-requested flag at the last two failure sites
The CommonJS module-function call and the ES module Evaluate failure only
recognized a termination V8 had already materialized. A request that landed
during the call, before any JS ran to materialize it, let an ordinary failure
be formatted as an error on a terminating isolate. Both sites now read the
same three signals as the settle pump and the require path.
* fix(worker): rethrow ordinary failures until a termination materializes
ReThrowToV8 skipped the throw whenever the runtime's termination-requested
flag was set. Between terminate() setting that flag and V8 delivering the
interrupt, JS still runs, so an ordinary native failure in that window
returned nothing: require() yielded undefined and a native constructor
handed back an uninitialized object, which a following call could trip an
assert on in Debug builds. The skip now keys on IsExecutionTerminating()
alone; inside a callback a materialized termination is never cleared on the
way up, so that signal is sufficient there.
Also gives the module-instantiate failure in LoadESModule the same
termination check as the runner's other failure sites, so a terminated link
is reported as an interruption rather than logged as an instantiation error.1 parent d02e43c commit 872aba9
10 files changed
Lines changed: 382 additions & 81 deletions
File tree
- NativeScript/runtime
- TestRunner/app/tests
- workerTerminate
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
561 | 564 | | |
562 | | - | |
| 565 | + | |
563 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
564 | 573 | | |
565 | | - | |
566 | | - | |
| 574 | + | |
567 | 575 | | |
568 | 576 | | |
569 | 577 | | |
| |||
607 | 615 | | |
608 | 616 | | |
609 | 617 | | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | 618 | | |
616 | 619 | | |
617 | 620 | | |
| |||
630 | 633 | | |
631 | 634 | | |
632 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
633 | 639 | | |
634 | 640 | | |
635 | 641 | | |
| |||
658 | 664 | | |
659 | 665 | | |
660 | 666 | | |
661 | | - | |
662 | | - | |
663 | | - | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
664 | 674 | | |
665 | 675 | | |
666 | 676 | | |
| |||
690 | 700 | | |
691 | 701 | | |
692 | 702 | | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
697 | 708 | | |
698 | 709 | | |
699 | 710 | | |
| |||
715 | 726 | | |
716 | 727 | | |
717 | 728 | | |
718 | | - | |
| 729 | + | |
719 | 730 | | |
720 | 731 | | |
721 | 732 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
262 | 265 | | |
263 | 266 | | |
264 | 267 | | |
| |||
293 | 296 | | |
294 | 297 | | |
295 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
296 | 308 | | |
297 | 309 | | |
298 | 310 | | |
| |||
882 | 894 | | |
883 | 895 | | |
884 | 896 | | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
885 | 903 | | |
886 | 904 | | |
887 | 905 | | |
| |||
1277 | 1295 | | |
1278 | 1296 | | |
1279 | 1297 | | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
1280 | 1307 | | |
1281 | 1308 | | |
1282 | 1309 | | |
| |||
1364 | 1391 | | |
1365 | 1392 | | |
1366 | 1393 | | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
1367 | 1421 | | |
1368 | 1422 | | |
1369 | 1423 | | |
1370 | 1424 | | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
1378 | | - | |
1379 | | - | |
1380 | | - | |
1381 | | - | |
1382 | | - | |
1383 | | - | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
1387 | | - | |
1388 | | - | |
1389 | | - | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
| 1425 | + | |
1393 | 1426 | | |
1394 | 1427 | | |
1395 | 1428 | | |
| |||
1411 | 1444 | | |
1412 | 1445 | | |
1413 | 1446 | | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
1414 | 1452 | | |
1415 | 1453 | | |
1416 | 1454 | | |
| |||
1434 | 1472 | | |
1435 | 1473 | | |
1436 | 1474 | | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
1437 | 1490 | | |
1438 | 1491 | | |
1439 | 1492 | | |
| |||
1513 | 1566 | | |
1514 | 1567 | | |
1515 | 1568 | | |
| 1569 | + | |
1516 | 1570 | | |
1517 | 1571 | | |
1518 | 1572 | | |
| |||
1536 | 1590 | | |
1537 | 1591 | | |
1538 | 1592 | | |
| 1593 | + | |
1539 | 1594 | | |
1540 | 1595 | | |
1541 | 1596 | | |
| |||
1597 | 1652 | | |
1598 | 1653 | | |
1599 | 1654 | | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
1600 | 1662 | | |
1601 | 1663 | | |
1602 | 1664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
333 | 342 | | |
334 | 343 | | |
335 | 344 | | |
336 | | - | |
| 345 | + | |
337 | 346 | | |
338 | 347 | | |
339 | 348 | | |
| |||
705 | 714 | | |
706 | 715 | | |
707 | 716 | | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
708 | 725 | | |
709 | 726 | | |
710 | 727 | | |
| |||
765 | 782 | | |
766 | 783 | | |
767 | 784 | | |
768 | | - | |
| 785 | + | |
769 | 786 | | |
770 | 787 | | |
771 | 788 | | |
| |||
0 commit comments