Thread overview
[Issue 23731] [REG2.102] Throwing within finalizers causes InvalidMemoryOperationError on Windows
Feb 22, 2023
Dlang Bot
Feb 22, 2023
Dlang Bot
Mar 01, 2023
Dlang Bot
February 22, 2023
https://issues.dlang.org/show_bug.cgi?id=23731

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #1 from Dlang Bot <dlang-bot@dlang.rocks> ---
@kinke updated dlang/dmd pull request #14901 "[stable] druntime: Fix InvalidMemoryOperation error on Windows when throwing exceptions from finalizers" fixing this issue:

- Fix Issue 23731 - InvalidMemoryOperation error on Windows when throwing exceptions from finalizers

  A v2.102 regression, which newly enabled `StackTrace` constructions
  from within GC finalizers. The construction is `@nogc`, but
  apparently depends on the `typeid(StackTrace)` monitor having been
  allocated already, i.e., a previous `StackTrace` construction.

  So pre-allocate a dedicated `Mutex` in the module constructor to
  make the `StackTrace` construction really `@nogc`.
  `druntime/test/allocations/src/alloc_from_assert.d` then passes on
  Windows again (not tested by DMD, but by LDC).

  While at it, also prevent `InvalidMemoryOperation` errors when trying
  to print exceptions within finalizers - by not resolving anything
  (=> empty printed trace), as resolving currently heavily depends on
  the GC.

https://github.com/dlang/dmd/pull/14901

--
February 22, 2023
https://issues.dlang.org/show_bug.cgi?id=23731

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #14901 "[stable] druntime: Fix InvalidMemoryOperation error on Windows when throwing exceptions from finalizers" was merged into stable:

- 936e7e26bbefeb2172686f5c828655ac9e521376 by Martin Kinkelin:
  Fix Issue 23731 - InvalidMemoryOperation error on Windows when throwing
exceptions from finalizers

  A v2.102 regression, which newly enabled `StackTrace` constructions
  from within GC finalizers. The construction is `@nogc`, but
  apparently depends on the `typeid(StackTrace)` monitor having been
  allocated already, i.e., a previous `StackTrace` construction.

  So pre-allocate a dedicated `Mutex` in the module constructor to
  make the `StackTrace` construction really `@nogc`.
  `druntime/test/allocations/src/alloc_from_assert.d` then passes on
  Windows again (not tested by DMD, but by LDC).

  While at it, also prevent `InvalidMemoryOperation` errors when trying
  to print exceptions within finalizers - by not resolving anything
  (=> empty printed trace), as resolving currently heavily depends on
  the GC.

https://github.com/dlang/dmd/pull/14901

--
March 01, 2023
https://issues.dlang.org/show_bug.cgi?id=23731

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #14938 "merge stable" was merged into master:

- a54fbab882b8a4c7fc86086dd1a414e9324dea6c by Martin Kinkelin:
  [stable] druntime: Fix InvalidMemoryOperation error on Windows when throwing
exceptions from finalizers (#14901)

  * Fix Issue 23731 - InvalidMemoryOperation error on Windows when throwing
exceptions from finalizers

  A v2.102 regression, which newly enabled `StackTrace` constructions
  from within GC finalizers. The construction is `@nogc`, but
  apparently depends on the `typeid(StackTrace)` monitor having been
  allocated already, i.e., a previous `StackTrace` construction.

  So pre-allocate a dedicated `Mutex` in the module constructor to
  make the `StackTrace` construction really `@nogc`.
  `druntime/test/allocations/src/alloc_from_assert.d` then passes on
  Windows again (not tested by DMD, but by LDC).

  While at it, also prevent `InvalidMemoryOperation` errors when trying
  to print exceptions within finalizers - by not resolving anything
  (=> empty printed trace), as resolving currently heavily depends on
  the GC.

  * [work around cyclic modules dependency...]

  * druntime: Test test/allocations/src/alloc_from_assert.d on Windows too

  As it regressed with v2.102.

https://github.com/dlang/dmd/pull/14938

--