[Haskell-cafe] Re: sendfile leaking descriptors on Linux?

Bardur Arantsson spam at scientician.net
Wed Feb 17 14:27:07 EST 2010


Jeremy Shaw wrote:
> On Wed, Feb 17, 2010 at 2:36 AM, Taru Karttunen <taruti at taruti.net> wrote:
> 
> 
> So for sendfile, instead of threadWaitWrite we could do:
> 
>  r <- timeout (60 * 10^6) threadWaitWrite
>  case r of
>    Nothing -> ... -- timed out
>    (Just ()) -> ... -- keep going
> 

For sendfile, a timeout of 1 second would probably be fine. The *ONLY* 
purpose of threadWaitWrite in the sendfile code is to avoid busy-waiting 
on EAGAIN from the native sendfile.

What would work is, instead of using threadWaitRead (as in the code you 
supplied) to simply have a 1 second timeout which causes the loop to 
call the native sendfile again. Native sendfile *will* fail with an 
error code if the socket has been disconnected.

With that in place "dead" threads waiting on threadWaitWrite will only 
linger at most 1 second before discovering the disconnect.

Not ideal, but a lot better than the current situation.

> Does that sound like the right fix to you?

[--snip--]

> (Obviously, if people are using sendfile with something other than happstack,
> it does not help them, but it  sounds like trying to fix things in
 > sendfile is misguided anyway.)
> 

How so? As a user I expect sendfile to work and not semi-randomly block 
threads indefinitely.

Cheers,



More information about the Haskell-Cafe mailing list