Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 50407
Status: rejected
Priority: 0/
Queue: CGI

People
Owner: MARKSTOS [...] cpan.org
Requestors: buuuzi [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



CGI.pm does not delete temporary file after processing file upload under mod_perl as promised in documentation. I have discovered a lot of files CGItemp***** in /var/tmp eating space. Perl 5.10 OpenSUSE 11.1 Latest apache/mod_perl
Subject: CGI.pm not cleaning up temp files under mod_perl
On Sun Oct 11 19:24:06 2009, raveland wrote: Show quoted text
> CGI.pm does not delete temporary file after processing file upload
under Show quoted text
> mod_perl as promised in documentation. I have discovered a lot of
files Show quoted text
> CGItemp***** in /var/tmp eating space. > > Perl 5.10 > OpenSUSE 11.1 > Latest apache/mod_perl
I use CGI.pm with mod_perl and don't have a bunch of temp files lying around. Are you able to reproduce this with a simple test case: 1. Upload a file 2. Observe that a temp file persists
Subject: Temporary file uplaods
On Mon Oct 12 08:49:17 2009, MARKSTOS wrote: Show quoted text
> I use CGI.pm with mod_perl and don't have a bunch of temp files lying > around. Are you able to reproduce this with a simple test case: > > 1. Upload a file > 2. Observe that a temp file persists
I have made some test, and yes, in fact, there is no error when loading cgi object into one script and using it from there. But this causes to leave temporary files: --- script.pl --- #!/usr/bin/perl use strict; use warnings; no warnings 'once'; use MyTest; my $obj = MyTest->new; print "Content-type: text/html\n\n"; my $filename = $MyTest::cgi->param('picture'); print $MyTest::cgi->tmpFileName($filename); # my own stuff with $obj->... --- end of script.pl -- --- MyTest.pm --- package MyTest; our ($cgi); sub new { my $class = shift; my %opts = @_; my $self = {}; $cgi = new CGI; bless ($self, $class); return $self; } 1; --- end of MyTest.pm ---
Subject: Re: [rt.cpan.org #50407] Temporary file uplaods
Date: Mon, 12 Oct 2009 12:00:05 -0400
To: bug-CGI.pm [...] rt.cpan.org
From: Mark Stosberg <mark [...] summersault.com>
Show quoted text
> But this causes to leave temporary files: > > our ($cgi);
That's because the use of "our" makes the object persisent beyond one request, which is generally considered a bug in the application code: http://perl.apache.org/docs/1.0/guide/porting.html#Global_Variables_Persistence I think you will find that that the web server is restarted or the process is killed, the temp files may be cleaned up then, because that's when the CGI object will be destroyed. If you are using the same CGI object across multiple requests, I consider that a bug in your code. I wouldn't be surprised if you you can now set a value on page and read it on the next (assuming you are in single server mode), which could be a significant bug, if not a security problem. According to the CGI.pm source code, this clean up happens when the object goes out of scope. Another reason that the object might be going out of scope is because your code has a circular reference to the object, so it can't be cleaned up automatically. That's also not a bug in CGI.pm. Mark
Hello, I understood my mistakes and beg to be forgiven. Now I observe different situation with the same problem. On machines with details above everything is fine - when the cgi object goes out of scope - it removes temp files. I have a problem with my new machine. Here's info: perl -v: This is perl, v5.10.0 built for x86_64-linux-thread-multi uname -a: Linux production-2 2.6.31.5-0.1-default #1 SMP 2009-10-26 15:49:03 +0100 x86_64 x86_64 x86_64 GNU/Linux Apache info: Apache/2.2.13 (Linux/SUSE) mod_perl/2.0.4 Perl/v5.10.0 The script which is run under mod_perl env, is simple: ------------------- #!/usr/bin/perl use strict; use warnings; no warnings 'once'; use CGI; my $cgi = CGI->new; print "Content-type: text/html\n\n"; print "Hello"; ------------------- However, it does not delete temporary files as all my other machines do. I have put some warning lines into your CGI.pm and discovered that main CGI object gets destroyed, but CGITempFile object never do. Could you please explain why some parts of module destroy fine, but some don't? Thanks.
Show quoted text
> The script which is run under mod_perl env, is simple: > ------------------- > #!/usr/bin/perl > > use strict; > use warnings; > no warnings 'once'; > > use CGI; > > my $cgi = CGI->new; > > print "Content-type: text/html\n\n"; > print "Hello"; > -------------------
I don't see how why script would create any tmp files. Does it for you? Show quoted text
> Could you please explain why some parts of module destroy fine, but
some don't? One reason is due to circular references. Is every module version of every other module in your project the same across all your machines? I suspect not. One of them could have a circular reference involving the "CGITempFile" name space but perhaps not the "CGI" name space for example. I am just guessing, but since CGI.pm did not change between your machines, there is a good chance that the source of the bug is elsewhere. Mark
From: buuuzi [...] yahoo.com
Hello, As far as I understand - my script never creates itself temporary files. It is done by CGI module when it gets specific form parameters. But it's not the point. I have created a simple multipart form in html file, which points to that simple script. If I provide file (i.e. upload it) then CGI is responsible for this. So my example should work, it works (removes temporary files) on almost all systems, except this new one. This is what I am trying to figure out. Also my mod_perl startup script is default. For this test I am not using ANY modules except these come with default apache installation. I have removed all my work from this test machine. I rule out fact something was made by me except for that simple script. How can we debug this why CGITempFile does not destroy?
On Mon Dec 21 18:25:50 2009, raveland wrote: Show quoted text
> Hello, > > As far as I understand - my script never creates itself temporary > files. It is done by CGI module when it gets specific form parameters. > But it's not the point. > > I have created a simple multipart form in html file, which points to > that simple script. If I provide file (i.e. upload it) then CGI is > responsible for this. So my example should work, it works (removes > temporary files) on almost all systems, except this new one. This is > what I am trying to figure out. > > Also my mod_perl startup script is default. For this test I am not > using ANY modules except these come with default apache installation.
I Show quoted text
> have removed all my work from this test machine. I rule out fact > something was made by me except for that simple script. > > How can we debug this why CGITempFile does not destroy?
I think you've run into classic mod_perl perl issues: Search for "CGI->new" from here: http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery If you want to re-open a ticket for a bug you are experiencing in mod_perl, please submit a script which follows the recommendations outlined here. Mark
A follow-up sent to me directly, stored here for reference: ### Hello, Mark!  Sorry I am writing to your email instead of Cpan bugtracking system, but this email is just information on how I managed to find the problem.  If you remember it was about not destroying cgi object properly.  Finally it was combination of factors. Apache was running with mpm-itk module and was behind nginx front-end. Interesting thing is that if uploading file directly to backend apache (without frondend) objects got destroyed properly, but with frontend they don't. I have changed from mpm-itk to regular, and problems disappeared.  It seems to be my current newest distribution offered by default this mpm-itk for apache for x64 platforms, which is buggy or something.  Just thought it would be interesting to share this information. Ben ###
Rejecting as apparent bug in mpm-itk