> A small program (which I haven't been able to strip down to a
> minimal *failing* version ;) repeatedly opens sockets and does the
> following (I tested with all permutations of hSetBuffering):
> 
>   Socket.connectTo ...
>   hPutStrLn h "Data"
>   hPutStr h d
>   debug Io "Reading..:"
>   c <- hGetContents h
>   debug Io "."
>   print c
>   debug Io "*"
> 
> After several loops, the program fails with:
> 
> Io: "Reading..:"
> Io: "."
> 
> Fail: failed
> Action: lazyRead
> Handle: {loc=<socket: 0>,type=semi-closed,binary=True,buffering=none}
> Reason: Bad file descriptor
> File: <socket: 0>

Hmm, interesting bug.  I think I know what the reason is, but a proper
fix will require some thought.  The attached patch should get you going,
but it has one undesirable effect: a semi-closed Handle won't be closed
immediately after all the data has been read from it, it'll only be
closed when the finalizer eventually runs.

Cheers,
        Simon

Attachment: diff
Description: diff

Reply via email to