[GHC] #1936: When lazy IO blocks, it blocks the whole runtime

GHC trac at galois.com
Mon Nov 26 21:16:52 EST 2007


#1936: When lazy IO blocks, it blocks the whole runtime
------------------------------------------+---------------------------------
 Reporter:  guest                         |          Owner:          
     Type:  bug                           |         Status:  new     
 Priority:  normal                        |      Milestone:          
Component:  Runtime System                |        Version:  6.8.1   
 Severity:  normal                        |     Resolution:          
 Keywords:  lazy IO getContents blocking  |     Difficulty:  Unknown 
 Testcase:                                |   Architecture:  Multiple
       Os:  Linux                         |  
------------------------------------------+---------------------------------
Changes (by duncan):

  * difficulty:  => Unknown

Comment:

 It may just be a bug in bytestring, since the above code works when you
 switch to ordinary getContents and
 hPutStr.

 The current lazy bytestring hGetContents calls this worker:
 {{{
 hGetContentsN :: Int -> Handle -> IO ByteString
 hGetContentsN k h = lazyRead
   where
     lazyRead = unsafeInterleaveIO loop

     loop = do
         c <- S.hGetNonBlocking h k
         --TODO: I think this should distinguish EOF from no
         -- data available the underlying POSIX call makes
         -- this distinction, returning either 0 or EAGAIN
         if S.null c
           then do eof <- hIsEOF h
                   if eof then return Empty
                          else hWaitForInput h (-1)
                            >> loop
           else do cs <- lazyRead
                   return (Chunk c cs)
 }}}

 where S.hGetNonBlocking is just a simple wrapper over hGetBufNonBlocking:

 {{{
 hGetNonBlocking h i = createAndTrim i $ \p -> hGetBufNonBlocking h p i
 }}}

 Mind you, we're only using primitives that should not block the whole
 runtime, so I can't see what the bug would be if it's in this code.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1936#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list