[GHC] #13247: hPutBufNonBlocking can block
GHC
ghc-devs at haskell.org
Thu Feb 9 00:14:56 UTC 2017
#13247: hPutBufNonBlocking can block
-------------------------------------+-------------------------------------
Reporter: nh2 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.2
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets: #13246, #13245
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
This simply escalates an existing TODO in the code base to a ticket.
The function `System.IO.hPutBufNonBlocking` [1] calls `hPutBuf'` with
`can_block = False`, which is commented as `Bool -- allow blocking?`
([https://github.com/ghc/ghc/blame/876b00ba25a615423f48b0cf9d443a9fd5dbd6f4/libraries/base/GHC/IO/Handle/Text.hs#L708-L713
relevant lines])
However, `hPutBuf'` calls `bufWrite`, inside which there's the comment
([https://github.com/ghc/ghc/blame/876b00ba25a615423f48b0cf9d443a9fd5dbd6f4/libraries/base/GHC/IO/Handle/Text.hs#L751
relevant line]):
{{{
if (...)
-- There's enough room in the buffer:
-- just copy the data in and update bufR.
then do ...
-- else, we have to flush
else do ...
old_buf' <- Buffered.flushWriteBuffer haDevice old_buf
-- TODO: we should do a non-blocking flush here
}}}
so it turns out that if there's not enough room in the `Handle` buffer,
then `hPutBufNonBlocking` will block.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13247>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list