Opened 12 years ago

Closed 12 years ago

#2109 closed bug (invalid)

hIsEOF blocks when applied to a non-closed socket with no input available

Reported by: Mads Owned by:
Priority: normal Milestone:
Component: libraries/base Version: 6.8.2
Keywords: hIsEOF blocks sockets Cc:
Operating System: Linux Architecture: x86
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

As shown with the attached test-programs, hIsEOF will block when applied to a socket-handle that is not closed and has no input available.

I believe that hIsEOF blocks, as it calls hLookAhead (see libraries/base/GHC/Handle.hs), which blocks when there is no input. Note that this is only a problem when using sockets, as (local) files will either be EOF or has some content.

If hIsEOF blocking nature is expected behaviour, then I think it should be noted in the haddock-documentation, as it seems non-obvious. Especially, as it will seem non-blocking when working with files.

I am using GHC 6.8.2 on a Debian Linux box.

To reproduce the bug, then first compile the test programs using the accompanying makefile. Then start the server. After that the client. As can be seen, the server will hang.

Attachments (3)

Makefile (182 bytes) - added by Mads 12 years ago.
Server.hs (335 bytes) - added by Mads 12 years ago.
Client.hs (215 bytes) - added by Mads 12 years ago.

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by Mads

Attachment: Makefile added

Changed 12 years ago by Mads

Attachment: Server.hs added

Changed 12 years ago by Mads

Attachment: Client.hs added

comment:1 Changed 12 years ago by Mads

Architecture: Multiplex86
Operating System: UnknownLinux

comment:2 Changed 12 years ago by mads

Resolution: invalid
Status: newclosed

When reporting this bug I thought that hIsEOF should return False, in the case described in the bug report. However, this may lead to trouble. Consider the following program:

do isEOF <- hIsEOF someHandle

when (not isEOF) (hGetLine someHandle >>= ...)

this program could fail, if "someHandle" was closed between the first and second line.

Also I re-read the documentation for hIsEOF and it starts with:

"For a readable handle hdl, ..." (http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html#v%3AhIsEOF)

so arguably the documentation actually says that hIsEOF may block. However, it would be nice, if the documentation said explicitly that hIsEOF could block.

Note: See TracTickets for help on using tickets.