#4514: IO manager can deadlock if a file descriptor is closed behind its back
---------------------------------+------------------------------------------
    Reporter:  adept             |       Owner:  tibbe                      
        Type:  bug               |      Status:  new                        
    Priority:  normal            |   Component:  Runtime System             
     Version:  7.0.1             |    Keywords:                             
    Testcase:                    |   Blockedby:                             
          Os:  Linux             |    Blocking:                             
Architecture:  Unknown/Multiple  |     Failure:  Incorrect result at runtime
---------------------------------+------------------------------------------

Comment(by adept):

 By the way, here is the standalone version of test:

 {{{
 module Main where

 import Control.Concurrent
 import Network
 import Network.Socket as S
 import System.IO
 import System.Timeout
 import Control.Monad

 main :: IO ()
 main = do
     s <- listenOn (Service "7000")
     forkIO $ loop s
     poll
     poll
     return ()

 poll :: IO ()
 poll = do
     hdl <- connectTo "localhost" (Service "7000")
     hSetBuffering hdl LineBuffering
     threadDelay 10000
     forM_ ["1","2","FINISH"] $ \str -> do
       hPutStrLn hdl str
       resp <- hGetLine hdl
       putStrLn $ "Sent " ++ str ++ ", got " ++ resp
     threadDelay 6000000
     hClose hdl

 loop :: Socket -> IO ()
 loop s = do
     (s',_) <- S.accept s
     forkIO $ echo s'
     loop s

 echo :: Socket -> IO ()
 echo s = do
     mstr <- timeout 5000000 $ recv s 1000
     case mstr of
         Just str -> do
             send s str
             echo s
         Nothing -> do
             putStrLn "Time out"
             sClose s
             return ()
 }}}

 Expected output:

 {{{
 Sent 1, got 1
 Sent 2, got 2
 Sent FINISH, got FINISH
 Time out
 Sent 1, got 1
 Sent 2, got 2
 Sent FINISH, got FINISH
 Time out
 }}}

 Instead we have:

 {{{
 Sent 1, got 1
 Sent 2, got 2
 Sent FINISH, got FINISH
 Time out
 Time out
 <socket: 11>: hGetLine: resource vanished (Connection reset by peer)
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4514#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to