
I desperation, I've tried to instrument a couple of the functions in SendFile:
sendFile'' :: Socket -> Handle -> Integer -> Integer -> IO () sendFile'' outs inp off count = do let out_fd = Fd (fdSocket outs) in_fd <- handleToFd inp putStrLn ("in_fd=" ++ show in_fd) finally (wrapSendFile' _sendFile out_fd in_fd off count) (do putStrLn ("SENDFILE DONE " ++ show in_fd) )
sendFile' :: Socket -> FilePath -> Integer -> Integer -> IO () sendFile' outs infp offset count = bracket (openBinaryFile infp ReadMode) (\h -> do putStrLn "CLOSING FILE!" hClose h putStrLn "FILE CLOSED!") (\inp -> sendFile'' outs inp offset count)
(Yes, this made me feel dirty.) Here's the resulting output from around when the file descriptor gets lost: --- Serving file 'X'... Sending 674465792 bytes... in_fd=7 SENDFILE DONE 7 CLOSING FILE! FILE CLOSED! hums: Network.Socket.SendFile.Linux: resource vanished (Broken pipe) Got request for CONTENT for objectId=1700000000000000,f215040000000000 Serving file 'X'... Sending 672892928 bytes... in_fd=7 SENDFILE DONE 7 CLOSING FILE! FILE CLOSED! hums: Network.Socket.SendFile.Linux: resource vanished (Broken pipe) Got request for CONTENT for objectId=1700000000000000,f215040000000000 Serving file 'X'... Sending 670140416 bytes... in_fd=7 <*----- What happened here? Got request for CONTENT for objectId=1700000000000000,f215040000000000 Serving file 'X'... Sending 667256832 bytes... in_fd=9 SENDFILE DONE 9 CLOSING FILE! FILE CLOSED! hums: Network.Socket.SendFile.Linux: resource vanished (Broken pipe) Got request for CONTENT for objectId=1700000000000000,f215040000000000 Serving file 'X'... Sending 665028608 bytes... in_fd=9 SENDFILE DONE 9 CLOSING FILE! FILE CLOSED! hums: Network.Socket.SendFile.Linux: resource vanished (Broken pipe) Got request for CONTENT for objectId=1700000000000000,f215040000000000 Serving file 'X'... --- Anyone got any clues as to what might cause the behavior show at the mark? The only idea I have is that *something* in the SendFile library kills the thread completely (or somehow evades "finally"), but I have no idea what it might be. Cheers,