[Haskell-cafe] Re: sendfile leaking descriptors on Linux?
spam at scientician.net
Sun Feb 7 10:22:35 EST 2010
Jeremy Shaw wrote:
> It's not clear to me that this is actually a bug in threadWaitWrite.
> I believe that under Linux, select() does not wakeup just because the file
> descriptor was closed.
select() has the option of specifying an "exceptfds" FD_SET where I'd
certainly _expect_ select() to flag an FD if it's closed. Annoyingly,
the man page is not very specific about what an "exception" is, so it's
hard to be sure.
> (Under Windows, and possibly solaris/BSD/etc it
> does). So this behavior might be consistent with normal Linux behavior.
> However, it is clearly annoying that (a) the expected behavior is not
> documented (b) the behavior might be different under Linux than other OSes.
> In some sense it is correct -- if the file descriptor is closed, then we
> certainly can't write more to it -- so threadWaitWrite need not wake up..
> But that leaves us with the issue of needing someway to be notified that
> the file descriptor was closed so that we can clean up after ourselves..
True, it is perhaps technically not a bug, but it is certainly a
misfeature since there is no easy way (at least AFAICT) to discover that
something bad has happened for the file descriptor and act accordingly.
AFAICT any solution would have to be based on a separate thread which
either 1) "checks" the FD periodically somehow, or 2) simply lets the
thread doing the threadWaitWrite time out after a set period of
inactivity. Neither is very optimal.
Either way, I'd certainly expect the sendfile library to work around
this somehow such that this situation doesn't occur. I'm just having a
hard time thinking up a good solution :).
More information about the Haskell-Cafe