Re: Apache::Upload bug?

2001-08-09 Thread Joe Schaefer

Jeffrey Hartmann [EMAIL PROTECTED] writes:

 After much tracing I found that the problem occurs in the command my
 $fh = $file-fh; where Apache::Upload dup()'s the filehandle and
 passed the duplicate to the perl script.  Then when the program exits
 the perl script still has an open filehandle to that file.  I fixed my
 problem by adding a close $$fh;  to my program which closed the
 duplicate filehandle. 

You have hit the nail on the head; the refcount for $$fh is too high.
I see the problem with apache1.3.19 + modperl 1.25 + perl 5.6.1, 
but I don't know if the same holds for earlier versions.  

It appears that the C code generated by xsubpp is the culprit, but I'm 
not exactly sure about this.

In the meantine, try inserting the following line at the top of the 
CLEANUP: section of ApacheUpload_fh in Request.xs:

  SvREFCNT_dec(SvRV(ST(0))); /* ~ line 523 in Request.xs */

It seems to do the trick for single file uploads.  Please let us
know if this fixes the problem for you.

 Now I'm not sure if this is a bug or if it's supposed to be like that, 
 but the documentation makes it sound like it gives you the actually 
 filehandle of the tempfile, and not a copy.  I just assumed that it 
 would be closed by Apache::Upload when the request was finished.

The duping behavior is desirable, but the filehandle remaining open 
is definitely a bug; and it may have been around for quite a while.

Thanks a bunch for fleshing it out.

-- 
Joe Schaefer




Apache::Upload bug?

2001-08-07 Thread Jeffrey Hartmann

Ok, for a the last couple days I've been searching out a problem I've been
having with Apache::Upload and Image::Magick.

The code consists mainly of::

@upload = $r-upload;
 foreach my $file (@upload)
{
my $fh = $file-fh;

# There's some .ext checking here to get $type and some renaming.

my $i = Image::Magick-new(magick=$type);
$err = $i-ReadImage(file=$$fh);
$i-Set(magick=$type);
$err = $i-WriteImage(filename=$filename));
warn $err if $err;
undef $i;
}


Now the main problem was that when the request was over the temp file
Apache::Upload creates, apreq??, in the /tmp directory was getting
unlink'd but there was still an open filehandle to it.  This meant that the
space the image was taking up on the /tmp dir was not being cleared, but the
file wasn't showing up in the directory.  And each image upload after this
was creating more stale filehandles and keeping more and more drive space
occupied.  If Apache was restarted the filehandles were closed and the
memory was free'd.  I assume when a child dies it also clears the memory,
but I'm not sure on that one.

After much tracing I found that the problem occurs in the command my $fh =
$file-fh; where Apache::Upload dup()'s the filehandle and passed the
duplicate to the perl script.  Then when the program exits the perl script
still has an open filehandle to that file.  I fixed my problem by adding a
close $$fh;  to my program which closed the duplicate filehandle.

Now I'm not sure if this is a bug or if it's supposed to be like that, but
the documentation makes it sound like it gives you the actually filehandle
of the tempfile, and not a copy.  I just assumed that it would be closed by
Apache::Upload when the request was finished.



-Jeff Hartmann