GC and weak reference finalizers and exceptions
When GC runs a number of finalizers in a row, and the first of them throws an exception, then other finalizers are ignored. The relevant piece of code is [here](https://github.com/ghc/ghc/blob/fb4092642f057f258d07cd6979925f4e2579eda6/libraries/base/GHC/Weak.hs#L144).
The following program reproduces the issue:
```
import Data.IORef
import Control.Monad
import Control.Exception
import System.Mem
main :: IO ()
main = do
run
run
run
run
performMajorGC
performMajorGC
run :: IO ()
run = do
ref <- newIORef ()
void $ mkWeakIORef ref $ do
putStr "."
throwIO $ ErrorCall "failed"
```
I expect it to output "....", but I get only "."
The issue makes it unsafe to rely on finalizer for resource cleanup because unrelated finalizer (e.g. from some other library) may prevent your finalizer from running.
Actually I was sure the issue is known, but today I tried to find a reference to it, and failed.
If it is by design, then it should be documented somewhere.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"GC and weak reference finalizers and exceptions","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"When GC runs a number of finalizers in a row, and the first of them throws an exception, then other finalizers are ignored. The relevant piece of code is [https://github.com/ghc/ghc/blob/fb4092642f057f258d07cd6979925f4e2579eda6/libraries/base/GHC/Weak.hs#L144 here].\r\n\r\nThe following program reproduces the issue:\r\n\r\n{{{\r\nimport Data.IORef\r\nimport Control.Monad\r\nimport Control.Exception\r\nimport System.Mem\r\n\r\nmain :: IO ()\r\nmain = do\r\n run\r\n run\r\n run\r\n run\r\n performMajorGC\r\n performMajorGC\r\n\r\nrun :: IO ()\r\nrun = do\r\n ref <- newIORef ()\r\n void $ mkWeakIORef ref $ do\r\n putStr \".\"\r\n throwIO $ ErrorCall \"failed\"\r\n}}}\r\n\r\nI expect it to output \"....\", but I get only \".\"\r\n\r\nThe issue makes it unsafe to rely on finalizer for resource cleanup because unrelated finalizer (e.g. from some other library) may prevent your finalizer from running.\r\n\r\nActually I was sure the issue is known, but today I tried to find a reference to it, and failed.\r\n\r\nIf it is by design, then it should be documented somewhere.","type_of_failure":"OtherFailure","blocking":[]} -->
issue