Thread overview
[Issue 20227] "Aborting from src/core/sync/event.d(141) Error: pthread_mutex_destroy failed." after fork()
Sep 18, 2019
Rainer Schuetze
Sep 19, 2019
Rainer Schuetze
Sep 19, 2019
Vladimir Panteleev
Sep 20, 2019
Dlang Bot
Sep 27, 2019
Dlang Bot
September 18, 2019
https://issues.dlang.org/show_bug.cgi?id=20227

Rainer Schuetze <r.sagitario@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario@gmx.de

--- Comment #1 from Rainer Schuetze <r.sagitario@gmx.de> ---
> 1. GC creates worker threads
> 2. Program forks, leaving the worker threads behind
> 3. The GC keeps working, though, without any worker threads to read
> from its queue, it does all the work in the main thread

That's about what I expected to happen. If the parent process hasn't started any collection, the fork will create its own set of scan threads.

> 4. On exit, the GC fails to destroy thread-related resources as it is not aware that the program has forked.

I didn't think of this. I wonder why the existing tests (e.g. in std.stdio) didn't fail, maybe because they didn't start any collection before forking.

I guess what needs to happen is to reinitialize thread handles and used mutices in an atfork child handler.

--
September 19, 2019
https://issues.dlang.org/show_bug.cgi?id=20227

--- Comment #2 from Rainer Schuetze <r.sagitario@gmx.de> ---
I just tried to reproduce the issue with dmd 2.088 in an Ubuntu 19 VM, but it passes without the error message. What kind of system do you use? Does it need some specific compile options?

--
September 19, 2019
https://issues.dlang.org/show_bug.cgi?id=20227

--- Comment #3 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
I can reproduce this issue on my home machine (Arch Linux x86_64, i7-4960X) and
my server (Ubuntu Server 16.04 x86_64, i7-7700). If it helps, I can get you an
ssh account on the server.

--
September 20, 2019
https://issues.dlang.org/show_bug.cgi?id=20227

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

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

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@rainers created dlang/druntime pull request #2805 "fix Issue 20227 - "Error: phread_mutex_destroy failed." after fork()" fixing this issue:

- fix Issue 20227 - "Aborting from src/core/sync/event.d(141) Error:
pthread_mutex_destroy failed." after fork()

  clear thread handles and events for parallel marking in child process after
fork

https://github.com/dlang/druntime/pull/2805

--
September 27, 2019
https://issues.dlang.org/show_bug.cgi?id=20227

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

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

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/druntime pull request #2805 "fix Issue 20227 - "Error: phread_mutex_destroy failed." after fork()" was merged into stable:

- e59c057c6c50f919131da5e508488be01de9cb05 by Rainer Schuetze:
  fix Issue 20227 - "Aborting from src/core/sync/event.d(141) Error:
pthread_mutex_destroy failed." after fork()

  clear thread handles and events for parallel marking in child process after
fork

https://github.com/dlang/druntime/pull/2805

--