Mailing List Archive

memory/caching problem?
We're experiencing a problem that may be some sort of bizarre memory
management problem in a Apache/FreeBSD/Perl CGI environment, and are
hoping someone else has seen or heard of something similar (not that
anyone would wish this on anybody else).

Software versions are:
Apache/1.3.20 (Unix)
FreeBSD 4.4-RELEASE #0
perl, v5.6.1 built for i386-freebsd

The symptom is as follows. Apache regularly runs perl CGI scripts
and all is usually ok. But on some occasions, one CGI execution
sees data from a different CGI execution (same script, different
request). By this I mean that one run of a CGI script has access
to, and can display, data from another execution of the same CGI
program. Interestingly, the data maps into the same variable names
in the perl program.

It's somewhat recreatable, but there is an element of apparent
randomness in it. We've theorized how any of the software components
listed above could be at fault, but have drawn a blank at uncovering
the cause so far.

Perhaps the only unusual thing about the error-prone CGI scripts
we've observed is that they are calling perl 'flock' (on a normal
file).

Can anyone help with this?

Thanks.

Dave Shaw


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: memory/caching problem? [ In reply to ]
Dave Shaw wrote:
>
> We're experiencing a problem that may be some sort of bizarre memory
> management problem in a Apache/FreeBSD/Perl CGI environment, and are
> hoping someone else has seen or heard of something similar (not that
> anyone would wish this on anybody else).
> .....
> Perhaps the only unusual thing about the error-prone CGI scripts
> we've observed is that they are calling perl 'flock' (on a normal
> file).

Aha! - if you're file-locking you must be writing and reading to/from
files... This is tricky on a busy server.

Remember that there are many httpd daemons running soncurrently on your
system and it is quite common for two or more CGI programs to run at the
same time. If they are all using the same file, it is quite easy to find
two or more instances reading and writing simultaneously. This will
cause no end of fun.

The fact that you already use "flock" indicates you are aware of this,
but I would guess that perhaps you haven't implemented all the locking
you need and that you still get some corruption. Work carefully through
your program and make sure that if it writes something to a file, noting
else can write to the same file until you're finished. A common mistake
is to do:

lock_file();
write_to_file();
unlock_file();

do_stuff();

lock_file();
read from_file();
unlock_file();

You should do:

lock_file();
write_to_file();

do_stuff();

read from_file();
unlock_file();

If there is a gap between writing and reading (i.e. separate invocations
of the program) then you need to use distict filenames for each process
and pass filenames between invocations using hidden parameters, etc.

Rgds,

Owen Boyle

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org