logo       

RE: hClose non-terminating: msg#00009

lang.haskell.glasgow.bugs

Subject: RE: hClose non-terminating


> I have a problem with a handle for which hClose does not
> terminate. Unfortunately
> it's too much work for me to narrow it down now, but perhaps
> it can be worked out
> from these facts?
> (1) it's a socket connection.
> (2) it has BlockBuffering (Just 4096) set.
> (3) it is possible that another thread is simultaneously
> trying to read from it.
> (4) hFlush on the same handle terminates.
> (5) if I remove the hClose the program terminates (presumably
> closing the connection) successfully.

Sorry for the delay in replying.

I think this is "expected behaviour" (or possibly a known bug). You can
demonstrate it like this:

main = do
forkIO (getChar >> return ())
yield
hClose stdin

The thread reading from the handle has a lock on it, so that hClose has
to wait before it can gain access to the handle to close it.

What would you like to happen in this case? I guess getChar could be
given an exception if the handle was closed underneath it. The problem
is that releasing the lock in the middle of getChar while it waits for
input is quite awkward to implement, and doing it in the middle of
getLine is even worse.

hFlush on the handle terminates because that only acts on the write side
of the handle, which has a separate lock from the read side.

My feeling is that this would be a pain to fix. Can you work around it?

Cheers,
Simon


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise