Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,391
    • Issues 4,391
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 375
    • Merge Requests 375
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #15312

Closed
Open
Opened 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
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#15312