Thread overview
[Issue 22616] Infinity loop instead of InvalidMemoryOperationError during GC routine
Dec 21, 2021
Mathias LANG
Dec 18, 2022
Dlang Bot
Dec 26, 2022
Dlang Bot
December 21, 2021
https://issues.dlang.org/show_bug.cgi?id=22616

--- Comment #1 from feklushkin.denis@gmail.com ---
Wrong stack trace attached, correct is:

#0  __GI___clock_nanosleep (clock_id=clock_id@entry=0, flags=flags@entry=0,
req=0x7fffffffdad0, rem=0x7fffffffdae0) at
../sysdeps/unix/sysv/linux/clock_nanosleep.c:67
#1  0x00007ffff7d053f3 in __GI___nanosleep (req=<optimized out>, rem=<optimized
out>) at ../sysdeps/unix/sysv/linux/nanosleep.c:25
#2  0x00005555555ba090 in core.thread.osthread.Thread.sleep(core.time.Duration)
()
#3  0x00005555555bd6c9 in core.internal.spinlock.SpinLock.yield(ulong) shared
()
#4  0x00005555555bd67a in core.internal.spinlock.SpinLock.lock() shared ()
#5  0x00005555555c6dcb in
core.internal.gc.impl.conservative.gc.ConservativeGC.runLocked!(core.internal.gc.impl.conservative.gc.ConservativeGC.mallocNoSync(ulong,
uint, ref ulong, const(TypeInfo)),
core.internal.gc.impl.conservative.gc.mallocTime,
core.internal.gc.impl.conservative.gc.numMallocs, ulong, uint, ulong,
const(TypeInfo)).runLocked(ref ulong, ref uint, ref ulong, ref const(TypeInfo))
()
#6  0x00005555555be702 in
core.internal.gc.impl.conservative.gc.ConservativeGC.malloc(ulong, uint,
const(TypeInfo)) ()
#7  0x000055555559d3db in gc_malloc ()
#8  0x0000555555599875 in _d_newclass ()
#9  0x00005555555a3029 in core.runtime.defaultTraceHandler(void*) ()
#10 0x000055555559db52 in _d_traceContext ()
#11 0x000055555559d942 in _d_createTrace ()
#12 0x0000555555598cbe in _d_throwdwarf ()
#13 0x00005555555c327c in
core.internal.gc.impl.conservative.gc.Gcx.fullcollect(bool) ()
#14 0x00005555555c78d4 in
core.internal.gc.impl.conservative.gc.ConservativeGC.runLocked!(core.internal.gc.impl.conservative.gc.ConservativeGC.fullCollectNoStack().go(core.internal.gc.impl.conservative.gc.Gcx*),
core.internal.gc.impl.conservative.gc.Gcx*).runLocked(ref
core.internal.gc.impl.conservative.gc.Gcx*) ()
#15 0x00005555555bfc54 in
core.internal.gc.impl.conservative.gc.ConservativeGC.fullCollectNoStack() ()
#16 0x00005555555bfbea in
core.internal.gc.impl.conservative.gc.ConservativeGC.collectNoStack() ()
#17 0x00005555555aac3f in gc_term ()
#18 0x000055555559da7b in rt_term ()
#19 0x0000555555598acb in rt.dmain2._d_run_main2(char[][], ulong, extern(C)
int(char[][]) function).runAll() ()
#20 0x00005555555989ad in rt.dmain2._d_run_main2(char[][], ulong, extern(C)
int(char[][]) function).tryExec(scope void() delegate) ()
#21 0x000055555559890e in _d_run_main2 ()
#22 0x000055555559866a in _d_run_main ()
#23 0x0000555555597712 in main (argc=1, argv=0x7fffffffe228) at
/usr/include/dmd/druntime/import/core/internal/entrypoint.d:29
#24 0x00007ffff7c627ed in __libc_start_main (main=0x5555555976f0 <main>,
argc=1, argv=0x7fffffffe228, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffe218) at ../csu/libc-start.c:332
#25 0x00005555555975ea in _start ()

--
December 21, 2021
https://issues.dlang.org/show_bug.cgi?id=22616

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel@disroot.o
                   |                            |rg

--- Comment #2 from moonlightsentinel@disroot.org ---
Bisection points to this PR: https://github.com/dlang/druntime/pull/3476

--
December 21, 2021
https://issues.dlang.org/show_bug.cgi?id=22616

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pro.mathias.lang@gmail.com

--- Comment #3 from Mathias LANG <pro.mathias.lang@gmail.com> ---
The key is:
```
#7  0x000055555559d3db in gc_malloc ()
#8  0x0000555555599875 in _d_newclass ()
#9  0x00005555555a3029 in core.runtime.defaultTraceHandler(void*) ()
#10 0x000055555559db52 in _d_traceContext ()
#11 0x000055555559d942 in _d_createTrace ()
#12 0x0000555555598cbe in _d_throwdwarf ()
```

So it means we hit
https://github.com/dlang/druntime/blob/fd9a45448244fb9dd4326520ad8526c540895eb0/src/core/runtime.d#L695
But that shouldn't be possible, since this function is guarded by a
`GC.inFinalizer` check that would lead to it returning...

--
December 21, 2021
https://issues.dlang.org/show_bug.cgi?id=22616

--- Comment #4 from moonlightsentinel@disroot.org ---
The problem here is that this line [1] is executed before the exception is rethrown - which calls `_d_throwdwarf` and ends up trying to allocate the DefaultTraceHandler.

[1] https://github.com/dlang/druntime/blob/fd9a45448244fb9dd4326520ad8526c540895eb0/src/core/internal/gc/impl/conservative/gc.d#L3141

--
December 18, 2022
https://issues.dlang.org/show_bug.cgi?id=22616

Steven Schveighoffer <schveiguy@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@gmail.com

--- Comment #5 from Steven Schveighoffer <schveiguy@gmail.com> ---
*** Issue 23555 has been marked as a duplicate of this issue. ***

--
December 18, 2022
https://issues.dlang.org/show_bug.cgi?id=22616

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

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

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@schveiguy updated dlang/dmd pull request #14710 "Remove GC for allocating traceinfo" fixing this issue:

- Remove GC for allocating traceinfo. Allow traces for
  InvalidMemoryOperationError and other sensitive errors.
  Fixes 20650,16641,22616.

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

--
December 26, 2022
https://issues.dlang.org/show_bug.cgi?id=22616

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

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

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #14710 "Avoid GC for allocating traceinfo" was merged into master:

- 374f20760e6c6183861dc599e1fb6379830a032a by Steven Schveighoffer:
  Avoid GC for allocating traceinfo. Allow traces for
  InvalidMemoryOperationError and other sensitive errors.
  Fixes 20650,16641,22616.

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

--