On Thu, Oct 30, 2008 at 12:20 PM, Hongli Lai <hongli / plan99.net> wrote:
> Roger Pack wrote:
>>
>> This is very interesting.  I may have run into something similar to it
>> before.  Do you have an example of it?
>
> You mean an example of the problem? I can't seem to be able to come up with
> a small, isolated code sample that shows the problem, but I do know that if
> I comment out the fix (closing IO objects), applications will raise
> Errno::EBADFD on some (but not all) platform and with certain versions of
> Rails.

Which OS's might those be?  I know that when a forked child process
exit's it closes the child's descriptors--do you think is what causes
it [i.e. it is closed in the parent but not the child or vice versa
and somehow that corrupts the descriptor for the others]?

>
>> Why do you close all file descriptors after fork?
>
> Phusion Passenger's spawn manager is connected to Apache through an
> anonymous Unix socket. This allows Apache to send spawn requests to the
> spawn manager. Rails application processes spawned by the spawn manager must
> not have this file descriptor open, because leaving it open is a hint to
> Apache that the spawn manager is still alive.

That must be the justification for closing "half a pipe" when you
communicate with a child and parent [forked] process via pipes [1].

I'd be happy to work with you more on the GC if you'd like, sometime.

Thanks for your insights.
-=R
[1] http://www.opengroup.org/onlinepubs/009695399/functions/pipe.html
-- but the fact that they do close sockets in a child and not a parent
and it still works seems contrary to the above.