Opened 5 years ago

Closed 5 years ago

#9377 closed bug (fixed)

forkProcess unnecessarily sets wait_foreign in hs_exit_

Reported by: edsko Owned by:
Priority: normal Milestone: 7.8.3
Component: Compiler Version: 7.8.3
Keywords: Cc: snoyberg, AndreasVoellmy
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D99
Wiki Page:

Description

During normal course of action in real_main a process is terminated with a call to

    shutdownHaskellAndExit(exit_status, 0 /* !fastExit */);

which is defined as

void shutdownHaskellAndExit(int n, int fastExit)
{
    if (!fastExit) {
        // even if hs_init_count > 1, we still want to shut down the RTS
        // and exit immediately (see #5402)
        hs_init_count = 1;

        // we're about to exit(), no need to wait for foreign calls to return.
        hs_exit_(rtsFalse);
    }

    stg_exit(n);
}

However, when we call forkProcess, the child process does not terminate in this manner, but instead calls

       hs_exit();                      // clean up and exit
       stg_exit(EXIT_SUCCESS);

instead, where hs_exit is defined as

void hs_exit(void)
{
    hs_exit_(rtsTrue);
    // be safe; this might be a DLL
}

Crucially, this means that, unlike the parent, the child process does wait for foreign calls to be terminated (it calls hs_exit_ with rtsTrue instead of rtsFalse).

I don't see a reason why the child process should terminate in a different manner to the parent, so I propose to change this so that forkProcess calls shutdownHaskellAndExit, just like real_main does.

Incidentally, this is the immediate cause for https://ghc.haskell.org/trac/ghc/ticket/9284 , although the patch proposed in this ticket is not sufficient to solve the problems with termination of the I/O manager in the general case (but I will let Andreas explain that in more detail :).

Change History (4)

comment:1 Changed 5 years ago by snoyberg

Cc: snoyberg added

comment:2 Changed 5 years ago by AndreasVoellmy

Cc: AndreasVoellmy added

comment:3 Changed 5 years ago by Austin Seipp <austin@…>

In 44853a157a394bf00d1fdfff1926a6d178d8018c/ghc:

Terminate in forkProcess like in real_main

Test Plan: validate

Reviewers: simonmar, austin

Reviewed By: simonmar, austin

Subscribers: phaskell, simonmar, relrod, carter

Differential Revision: https://phabricator.haskell.org/D99

GHC Trac Issues: #9377

comment:4 Changed 5 years ago by MikolajKonarski

Milestone: 7.8.3
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.