Commit 9e1df01
authored
*shared* druntime: Avoid aborting with '_handleToDSO not in sync with _loadedDSOs' (#5048)
This error currently happens when a D DSO is unloaded in a thread the DSO
wasn't registered with. So for example, loading a D Python extension DLL
via dlopen/LoadLibrary in a Python worker thread (dragging in the druntime
and Phobos DLLs etc., and initializing those in the worker thread), and
one of the D DLLs then being unloaded in the Python *main* thread at
Python exit.
druntime has no way of registering the unknown main thread with druntime
(registering the OS-initialized TLS data with the D GC, running the TLS
module ctors etc.). [Normally, if you spawn a new thread via druntime,
then that new thread inherits all the DSOs registered with the parent
thread.]
What we currently do in case a DSO is unloaded in such a thread is still
running the TLS module dtors (as well as the shared module dtors etc.) of
that DSO, but then printing that 'not in sync' message and aborting the
process, so not finalizing any remaining DSOs.
Try to handle such scenarios more gracefully by
* emitting a stderr warning (per unloaded DSO) instead of aborting (and
so not skipping any remaining DSOs anymore, as well as not tampering
with the exit code),
* emitting the warning *before* the DSO finalization, so that any
issues there are easier to troubleshoot, and
* excluding the TLS module dtors for such not-registered-in-current-thread
DSOs, as the TLS module ctors most likely haven't run either in that
thread.1 parent 7222867 commit 9e1df01
1 file changed
Lines changed: 45 additions & 24 deletions
File tree
- runtime/druntime/src/rt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
645 | 645 | | |
646 | 646 | | |
647 | 647 | | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | 648 | | |
| 649 | + | |
658 | 650 | | |
659 | 651 | | |
660 | | - | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
661 | 661 | | |
662 | | - | |
663 | | - | |
664 | | - | |
665 | 662 | | |
666 | 663 | | |
667 | 664 | | |
668 | 665 | | |
669 | | - | |
| 666 | + | |
670 | 667 | | |
671 | 668 | | |
672 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
673 | 677 | | |
| 678 | + | |
674 | 679 | | |
675 | | - | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
676 | 701 | | |
677 | 702 | | |
678 | 703 | | |
679 | 704 | | |
680 | 705 | | |
681 | 706 | | |
| 707 | + | |
682 | 708 | | |
683 | 709 | | |
684 | 710 | | |
685 | 711 | | |
686 | 712 | | |
687 | | - | |
688 | | - | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
| 713 | + | |
694 | 714 | | |
695 | | - | |
696 | 715 | | |
697 | 716 | | |
698 | 717 | | |
| |||
898 | 917 | | |
899 | 918 | | |
900 | 919 | | |
901 | | - | |
| 920 | + | |
902 | 921 | | |
903 | 922 | | |
904 | 923 | | |
905 | 924 | | |
| 925 | + | |
906 | 926 | | |
| 927 | + | |
907 | 928 | | |
908 | 929 | | |
909 | 930 | | |
| |||
0 commit comments