named pipes memory leak?

Don Lewis truckman at FreeBSD.org
Mon Nov 10 14:32:12 PST 2003


On 10 Nov, Lukas Ertl wrote:
> On Mon, 10 Nov 2003, Don Lewis wrote:
> 
>> On 10 Nov, Lukas Ertl wrote:
>> >
>> > The following shell script freezes a machine in several minutes and needs
>> > a power cycle.  You can see the increasing memory in vmstat -z (unpcb) and
>> > netstat -u.  The kernel is FreeBSD 5.1-CURRENT Tue Nov 4 14:08:23 CET 2003.
>> >
>> > ---8<---
>> > #/bin/sh
>> >
>> > FIFO=/tmp/foo
>> >
>> > for i in `jot 50000 1`; do
>> >    mkfifo ${FIFO}
>> >    echo blubb > ${FIFO} &
>> >    kill $!
>> >    rm ${FIFO}
>> > done
>> > ---8<---
>>
>> If fifo_open() is interrupted, fifo_close() never gets called, and the
>> resources are not recovered.  I wish doing the resource recovery in
>> fifo_inactive() would have worked ...
>>
>> Try this patch:
> 
> Thanks, your patch seems so solve this problem effectively.

The patch has been committed.  Thanks for testing it.

BTW, I encountered a process leak when running your script.  The kill
would sometimes fail to find the process, maybe about 10% of the time. I
think maybe $! hadn't yet been updated and the shell was trying to kill
the previous echo process a second time.  The mkfifo would also fail
sometimes because the file already existed.  I think what the background
shell didn't get around to opening the fifo until after rm had nuked it
causing a plain file to get created.  Hmn, these events seemed to be
associated, so maybe the shell was creating a file and the next echo
command would write to the file and exit before the kill command was
executed.  This doesn't explain all those copies of sh stuck in the
"fifow" state, though.  Adding a "sleep 1" before the kill command seems
to make things work better.


More information about the freebsd-current mailing list