Ticket #1177 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

All I/O requests must complete before shutdown on Windows

Reported by: simonmar Owned by: simonmar
Priority: highest Milestone: 6.8.1
Component: Runtime System Version: 6.6
Keywords: Cc: kyrab@…
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

In the non-threaded RTS, in order to fix problems with shutdown of DLLs we made it so that the RTS would wait for any outstanding IO request threads to exit before the RTS exits (otherwise the threads return later to find the DLL is missing and crash).

Unfortunately this means if you fire off a long threadDelay and then the program ends, the RTS won't exit until the threadDelay expires, even if the original Haskell thread has been killed. In the threaded RTS, we don't have the threadDelay problem (any more) because of the IO manager thread, but we do have a similar problem with outstanding I/O requests (untested).

It's perhaps worse in the threaded RTS, because we don't wait for these I/O requests to exit - they are in foreign calls, and we don't currently wait for foreign calls to complete before exiting (this is a bug, in fact, similar to the original DLL shutdown bug).

I'm not sure what to do, here are some options:

  • the I/O request threads should be terminated, somehow.
  • maybe we need two ways to shut down the RTS: forcibly, for program exit, and more carefully, for DLL shutdown.
  • when shutting down a DLL, we should wait for and/or terminate outstanding foreign call threads.

Change History

Changed 6 years ago by simonmar

  • priority changed from normal to high
  • milestone changed from 6.6.2 to 6.8

Changed 6 years ago by guest

  • cc kyrab@… added

Changed 6 years ago by guest

  • cc Bulat.Ziganshin@… added; kyrab@… removed

i've seen problems like this with 6.6.1: after exitWith or finishing 'main' program frees all memory used and sleeps forever (at least several hours). i've "solved" problem by using C exit(), but strongly prefer to have real solution

Changed 6 years ago by guest

  • cc kyrab@… added; Bulat.Ziganshin@… removed

Changed 6 years ago by p_tanski

  • cc kyrab@… added; kyrab@… removed

Changed 6 years ago by guest

  • cc kyrab@… added; kyrab@… removed

Changed 6 years ago by simonmar

  • priority changed from high to highest

This is winning the length(CC_list) competition so far

Changed 6 years ago by simonmar

Nearly fixed. I implemented the latter two of the three options:

  • maybe we need two ways to shut down the RTS: forcibly, for program exit, and more carefully, for DLL shutdown.
  • when shutting down a DLL, we should wait for and/or terminate outstanding

So now program exit doesn't wait for threads to complete, but DLL shutdown does. Fortunately this was possible because DLL shutdown calls hs_exit() or equivalently shutdownHaskell(), but program exit calls shutdownHaskellAndExit(). hs_exit() now assumes the worst; namely that the RTS is about to go away, so it must ensure that any threads which might return to RTS code have completed.

I'll add some more documentation about DLL shutdown before I close this bug.

Changed 6 years ago by simonmar

  • status changed from new to closed
  • resolution set to fixed

I've now committed the documentation updates, this closes the bug.

Changed 6 years ago by igloo

  • milestone changed from 6.8 branch to 6.8.1

Changed 5 years ago by simonmar

  • architecture changed from Multiple to Unknown/Multiple
Note: See TracTickets for help on using tickets.