[GHC] #7170: Foreign.Concurrent finalizer called twice in some cases

GHC ghc-devs at haskell.org
Mon Jun 1 20:33:58 UTC 2015


#7170: Foreign.Concurrent finalizer called twice in some cases
-------------------------------------+-------------------------------------
        Reporter:  joeyadams         |                   Owner:  niteria
            Type:  bug               |                  Status:  patch
        Priority:  high              |               Milestone:  7.6.1
       Component:  Core Libraries    |                 Version:  7.8.3
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Runtime crash     |  Unknown/Multiple
      Blocked By:                    |               Test Case:
 Related Tickets:                    |  ffi/should_run/7170
                                     |                Blocking:
                                     |  Differential Revisions:  D921
-------------------------------------+-------------------------------------

Comment (by Simon Marlow <marlowsd@…>):

 In [changeset:"dfdc50d666498c5a1118557d67209fe067c61cc1/ghc"]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="dfdc50d666498c5a1118557d67209fe067c61cc1"
 Don't call DEAD_WEAK finalizer again on shutdown (#7170)

 Summary:
 There's a race condition like this:

   # A foreign pointer gets promoted to the last generation
   # It has its finalizer called manually
   # We start shutting down the runtime in `hs_exit_` from the main
     thread
   # A minor GC starts running (`scheduleDoGC`) on one of the threads
   # The minor GC notices that we're in `SCHED_INTERRUPTING` state and
     advances to `SCHED_SHUTTING_DOWN`
   # The main thread tries to do major GC (with `scheduleDoGC`), but it
     exits early because we're in `SCHED_SHUTTING_DOWN` state
   # We end up with a `DEAD_WEAK` left on the list of weak pointers of
     the last generation, because it relied on major GC removing it from
     that list

 This change:
   * Ignores DEAD_WEAK finalizers when shutting down
   * Makes the major GC on shutdown more likely
   * Fixes a bogus assert

 Test Plan:
 before this diff https://ghc.haskell.org/trac/ghc/ticket/7170#comment:5
 reproduced and after it doesn't

 Reviewers: ezyang, austin, simonmar

 Reviewed By: simonmar

 Subscribers: bgamari, thomie

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

 GHC Trac Issues: #7170
 }}}

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7170#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list