Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,249
    • Issues 5,249
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 578
    • Merge requests 578
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #15312
Closed
Open
Issue created Jun 26, 2018 by David Feuer@treeowlReporter

getChanContents exception behavior seems a bit odd

I've been playing around with Control.Concurrent.Chan today. Something seems a bit off:

-- Bug.hs
import Control.Concurrent (forkIO, yield)
import Control.Concurrent.Chan
import Data.List (elem)
import Control.Exception
import Control.Concurrent.MVar

data Ex = Ex deriving Show
instance Exception Ex

main = do
  ch <- newChan
  sync1 <- newEmptyMVar
  sync2 <- newEmptyMVar
  forkIO $ do {writeList2Chan ch [1..3*10^6 :: Int]; putMVar sync1 ()}
  yield
  writeChan ch (-12)
  cont <- getChanContents ch

  tid <- forkIO $ do
           evaluate (last cont)
           putMVar sync2 ()

  yield
  throwTo tid Ex


  print (elem (3*10^6) cont)
  takeMVar sync1
  tryTakeMVar sync2

When I run this single-threaded (+RTS -N1), it prints

Bug: Ex
Bug: Ex

One of the thunks in the lazy list gets overwritten by the (asynchronous) exception. This seems a bit surprising; is it the way it should be? Does hGetContents do this too?

Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Core Libraries
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking