[GHC] #6153: writeChan not properly protecting again async exceptions
GHC
cvs-ghc at haskell.org
Fri Jun 8 20:42:40 CEST 2012
#6153: writeChan not properly protecting again async exceptions
------------------------------+---------------------------------------------
Reporter: klao | Owner:
Type: bug | Status: new
Priority: normal | Component: libraries/base
Version: 7.4.1 | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Testcase:
Blockedby: | Blocking:
Related: |
------------------------------+---------------------------------------------
In the current code of writeChan from Control.Concurrent.Chan:
{{{
writeChan (Chan _ writeVar) val = do
new_hole <- newEmptyMVar
modifyMVar_ writeVar $ \old_hole -> do
putMVar old_hole (ChItem val new_hole)
return new_hole
}}}
if an async exception arrives "between" putMVar old_hole and return, the
channel will be left in inconsistent state: the writeVar will be reverted
to its original value, but old_hole would remain filled in. Thus all
subsequent writers will block on this Chan indefinitely.
The proper solution is to just mask the whole operation. And it's OK, as
'putMVar old_hole' cannot ever block. I attach a patch for this.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6153>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list