Bug 1861627 Comment 4 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

```
#12 0x00007f543a6b6ed7 in std::terminate() () at /lib/x86_64-linux-gnu/libstdc++.so.6
#13 0x00007f542a4a539d in std::thread::~thread (this=0x7f543a4008e0 <_IO_stdfile_2_lock>) at /home/alex/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/thread:140
#14 mozilla::DefaultDelete<std::thread>::operator() (this=0x7f5422d073c8, aPtr=0x7f543a4008e0 <_IO_stdfile_2_lock>) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:459
#15 mozilla::UniquePtr<std::thread, mozilla::DefaultDelete<std::thread> >::reset (this=0x7f5422d073c8, aPtr=0x0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:301
#16 mozilla::UniquePtr<std::thread, mozilla::DefaultDelete<std::thread> >::~UniquePtr (this=0x7f5422d073c8) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:249
#17 mozilla::MockCubeb::ThreadFunction()::$_1::~$_1() (this=0x7f5422d073c8) at /home/alex/codaz/Mozilla/gecko-cinnabar/dom/media/gtest/MockCubeb.cpp:705
#18 mozilla::detail::RunnableFunction<mozilla::MockCubeb::ThreadFunction()::$_1>::~RunnableFunction() (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsThreadUtils.h:539
#19 mozilla::detail::RunnableFunction<mozilla::MockCubeb::ThreadFunction()::$_1>::~RunnableFunction() (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsThreadUtils.h:539
#20 0x00007f542af19e18 in mozilla::Runnable::Release (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/xpcom/threads/nsThreadUtils.cpp:66
#21 0x00007f542af36af9 in mozilla::RefPtrTraits<nsIRunnable>::Release (aPtr=0x7f543a4008e0 <_IO_stdfile_2_lock>, aPtr@entry=0x7f541fb32d18) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/RefPtr.h:54
#22 nsCOMPtr<nsIRunnable>::~nsCOMPtr (this=0x7f541fb32d40) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsCOMPtr.h:344
#23 NS_DispatchBackgroundTask (aEvent=..., aDispatchFlags=aDispatchFlags@entry=0) at /home/alex/codaz/Mozilla/gecko-cinnabar/xpcom/threads/nsThreadUtils.cpp:521
#24 0x00007f542a460a2c in mozilla::MockCubeb::ThreadFunction (this=0x7f54235c9480) at /home/alex/codaz/Mozilla/gecko-cinnabar/dom/media/gtest/MockCubeb.cpp:704
```

`NS_DispatchBackgroundTask()` will release [its reference](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadUtils.cpp#518) to the runnable if `nsThreadManager::DispatchToBackgroundThread()` [fails](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadManager.cpp#517).  Presumably that is failing due to shutdown having advanced beyond `ShutdownNonMainThreads()`.

Perhaps the `std::terminate` might be due to destruction of the `std::thread` without `join()`.

`NS_DispatchToMainThread()` [will succeed a little longer during shutdown](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/build/XPCOMInit.cpp#628,668).  Comment 1 indicates that that will [still not be long enough](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/build/XPCOMInit.cpp#709), but when `NS_DispatchToMainThread()` fails, it would [leak the `std::thread`](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadUtils.cpp#233) without crashing.
```
#12 0x00007f543a6b6ed7 in std::terminate() () at /lib/x86_64-linux-gnu/libstdc++.so.6
#13 0x00007f542a4a539d in std::thread::~thread (this=0x7f543a4008e0 <_IO_stdfile_2_lock>) at /home/alex/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/thread:140
#14 mozilla::DefaultDelete<std::thread>::operator() (this=0x7f5422d073c8, aPtr=0x7f543a4008e0 <_IO_stdfile_2_lock>) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:459
#15 mozilla::UniquePtr<std::thread, mozilla::DefaultDelete<std::thread> >::reset (this=0x7f5422d073c8, aPtr=0x0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:301
#16 mozilla::UniquePtr<std::thread, mozilla::DefaultDelete<std::thread> >::~UniquePtr (this=0x7f5422d073c8) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:249
#17 mozilla::MockCubeb::ThreadFunction()::$_1::~$_1() (this=0x7f5422d073c8) at /home/alex/codaz/Mozilla/gecko-cinnabar/dom/media/gtest/MockCubeb.cpp:705
#18 mozilla::detail::RunnableFunction<mozilla::MockCubeb::ThreadFunction()::$_1>::~RunnableFunction() (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsThreadUtils.h:539
#19 mozilla::detail::RunnableFunction<mozilla::MockCubeb::ThreadFunction()::$_1>::~RunnableFunction() (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsThreadUtils.h:539
#20 0x00007f542af19e18 in mozilla::Runnable::Release (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/xpcom/threads/nsThreadUtils.cpp:66
#21 0x00007f542af36af9 in mozilla::RefPtrTraits<nsIRunnable>::Release (aPtr=0x7f543a4008e0 <_IO_stdfile_2_lock>, aPtr@entry=0x7f541fb32d18) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/RefPtr.h:54
#22 nsCOMPtr<nsIRunnable>::~nsCOMPtr (this=0x7f541fb32d40) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsCOMPtr.h:344
#23 NS_DispatchBackgroundTask (aEvent=..., aDispatchFlags=aDispatchFlags@entry=0) at /home/alex/codaz/Mozilla/gecko-cinnabar/xpcom/threads/nsThreadUtils.cpp:521
#24 0x00007f542a460a2c in mozilla::MockCubeb::ThreadFunction (this=0x7f54235c9480) at /home/alex/codaz/Mozilla/gecko-cinnabar/dom/media/gtest/MockCubeb.cpp:704
```

`NS_DispatchBackgroundTask()` will release [its reference](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadUtils.cpp#518) to the runnable if `nsThreadManager::DispatchToBackgroundThread()` [fails](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadManager.cpp#517).  Presumably that is failing due to shutdown having advanced beyond `ShutdownNonMainThreads()`.

Perhaps the `std::terminate` might be due to destruction of the `std::thread` without `join()`.

`NS_DispatchToMainThread()` [would succeed a little longer during shutdown](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/build/XPCOMInit.cpp#628,668).  Comment 1 indicates that that will [still not be long enough](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/build/XPCOMInit.cpp#709), but when `NS_DispatchToMainThread()` fails, it would [leak the `std::thread`](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadUtils.cpp#233) without crashing.
```
#12 0x00007f543a6b6ed7 in std::terminate() () at /lib/x86_64-linux-gnu/libstdc++.so.6
#13 0x00007f542a4a539d in std::thread::~thread (this=0x7f543a4008e0 <_IO_stdfile_2_lock>) at /home/alex/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/thread:140
#14 mozilla::DefaultDelete<std::thread>::operator() (this=0x7f5422d073c8, aPtr=0x7f543a4008e0 <_IO_stdfile_2_lock>) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:459
#15 mozilla::UniquePtr<std::thread, mozilla::DefaultDelete<std::thread> >::reset (this=0x7f5422d073c8, aPtr=0x0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:301
#16 mozilla::UniquePtr<std::thread, mozilla::DefaultDelete<std::thread> >::~UniquePtr (this=0x7f5422d073c8) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/UniquePtr.h:249
#17 mozilla::MockCubeb::ThreadFunction()::$_1::~$_1() (this=0x7f5422d073c8) at /home/alex/codaz/Mozilla/gecko-cinnabar/dom/media/gtest/MockCubeb.cpp:705
#18 mozilla::detail::RunnableFunction<mozilla::MockCubeb::ThreadFunction()::$_1>::~RunnableFunction() (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsThreadUtils.h:539
#19 mozilla::detail::RunnableFunction<mozilla::MockCubeb::ThreadFunction()::$_1>::~RunnableFunction() (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsThreadUtils.h:539
#20 0x00007f542af19e18 in mozilla::Runnable::Release (this=0x7f5422d073a0) at /home/alex/codaz/Mozilla/gecko-cinnabar/xpcom/threads/nsThreadUtils.cpp:66
#21 0x00007f542af36af9 in mozilla::RefPtrTraits<nsIRunnable>::Release (aPtr=0x7f543a4008e0 <_IO_stdfile_2_lock>, aPtr@entry=0x7f541fb32d18) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/mozilla/RefPtr.h:54
#22 nsCOMPtr<nsIRunnable>::~nsCOMPtr (this=0x7f541fb32d40) at /home/alex/codaz/Mozilla/gecko-cinnabar/obj-browser-dbg/dist/include/nsCOMPtr.h:344
#23 NS_DispatchBackgroundTask (aEvent=..., aDispatchFlags=aDispatchFlags@entry=0) at /home/alex/codaz/Mozilla/gecko-cinnabar/xpcom/threads/nsThreadUtils.cpp:521
#24 0x00007f542a460a2c in mozilla::MockCubeb::ThreadFunction (this=0x7f54235c9480) at /home/alex/codaz/Mozilla/gecko-cinnabar/dom/media/gtest/MockCubeb.cpp:704
```

`NS_DispatchBackgroundTask()` will release [its reference](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadUtils.cpp#518) to the runnable if `nsThreadManager::DispatchToBackgroundThread()` [fails](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadManager.cpp#517).  Presumably that is failing due to shutdown having advanced beyond `ShutdownNonMainThreads()`.

Perhaps the `std::terminate` might be due to destruction of the `std::thread` without `join()`.

`NS_DispatchToMainThread()` [would succeed a little longer during shutdown](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/build/XPCOMInit.cpp#628,668).  Comment 1 indicates that that would [still not be long enough](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/build/XPCOMInit.cpp#709), but when `NS_DispatchToMainThread()` fails, it would [leak the `std::thread`](https://searchfox.org/mozilla-central/rev/01a0d864a9442d0fe2dbd4beee5c88b9b46e96bd/xpcom/threads/nsThreadUtils.cpp#233) without crashing.

Back to Bug 1861627 Comment 4