Skip to content

Handling BlockedIndefinitelyOnMVar breaks other MVars

Summary

If I handle BlockedIndefinitelyOnMVar in one thread then write to a different MVar in that same thread, a thread trying to read the second MVar gets BlockedIndefinitelyOnMVar

Steps to reproduce

module Main where

import Control.Concurrent
import Control.Exception

main :: IO ()
main = do
  begin <- newEmptyMVar
  middle <- newEmptyMVar
  _ <- forkIO $ do
    handle (\BlockedIndefinitelyOnMVar -> pure ()) $ takeMVar begin
    putMVar middle ()
  takeMVar middle

Actual behavior

Program exits with "thread blocked indefinitely in an MVar operation" and code 1

Expected behavior

Program exits silently with code 0.

Environment

  • GHC version used: 9.2.4

Optional:

  • Operating System: Linux (NixOS)
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information