
#14503: Killing a thread will block if there is another process reading from a handle -------------------------------------+------------------------------------- Reporter: dnadales | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: libraries/base | Version: 8.0.2 Resolution: fixed | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dnadales): Reading from sockets leads to the same behavior. However, closing the socket before killing the thread works: {{{#!hs import qualified Data.ByteString.Char8 as C import Network.Socket hiding (recv, recvFrom, send, sendTo) import Network.Socket.ByteString readWithinNSecsBinary :: IO () readWithinNSecsBinary = withSocketsDo $ do addrinfos <- getAddrInfo Nothing (Just "") (Just "9090") let serveraddr = head addrinfos sock <- socket (addrFamily serveraddr) Stream defaultProtocol connect sock (addrAddress serveraddr) readerTid <- forkIO $ sockReader sock threadDelay (3 * 10^6) putStrLn "Killing the binary reader" putStrLn "Closing the socket" close sock -- Wihout this line the client will block putStrLn "Socket closed!" killThread readerTid putStrLn "Binary reader thread killed" where sockReader sock = do putStrLn "Receiving ..." msg <- recv sock 1024 putStr "Received " C.putStrLn msg }}} This results in {{{#!text Receiving ... Killing the binary reader Closing the socket Socket closed! dangling-connections-exe.EXE: Network.Socket.recvBuf: failed (No error) Binary reader thread killed }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14503#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler