[BUG] PerlCleanUpHandler seems to execute before reply

Cone - Sergei Kirjanov <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
PerlCleanUpHandle, that is registered in config executes before reply to the client.
So any time-consuming action in the cleanup handler affects response time without any notion.

This problem can be workarounded by using $ap->pool->cleanup_register(...), that works as expected.

------------------------ details ----------------------

This problem seeems to appear with mod_perl/2.0.9:
ubuntu 14.04: Apache/2.4.7 (Ubuntu) mod_perl/2.0.8 Perl/v5.18.2 -- ok
ubuntu 16.04: Apache/2.4.18 (Ubuntu) mod_perl/2.0.9 Perl/v5.22.1 -- not ok
ubuntu 18.04: Apache/2.4.29 (Ubuntu) mod_perl/2.0.10 Perl/v5.26.1 -- not ok, target
ubuntu 20.04: Apache/2.4.41 (Ubuntu) mod_perl/2.0.11 Perl/v5.30.0 -- not ok

apache.conf:
LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so
LoadModule authz_core_module /usr/lib/apache2/modules/mod_authz_core.so
Listen 1080
PidFile /web/.pid
ErrorLog /web/error.log
CustomLog /web/main.log main
ServerName cone2
PerlRequire /web/test.pl
SetHandler perl-script
PerlResponseHandler tnlib::sqcon::handler
PerlCleanUpHandler tnlib::sqcon::cleanuphandler

test.pl:
package tnlib::sqcon;
use strict;
use Apache2::Const qw(OK);
use Apache2::RequestRec ();
use APR::Pool ();
sub handler{
  my($ap)=@_;
  $ap->pool->cleanup_register(sub{ sleep 5; die 5 });
  $ap->status(200);
  return OK;
}
sub cleanuphandler{
  sleep 5;
}
1;

init.pl:
mkdir "/web/root";
system "/usr/sbin/apache2", "-f", "/web/apache.conf";
system "tail -f /web/main.log /web/error.log";

Dockerfile:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update && apt install -y netcat-openbsd curl mc libapache2-mod-perl2 libcgi-pm-perl && rm -rf /var/lib/apt/lists/*
RUN useradd --home-dir /web --create-home --user-group --uid 1979 --shell /bin/bash c2
COPY --chown=c2:c2 . /web/
USER c2
CMD ["perl","/web/init.pl"]

docker build -t apache_cleanup .
docker run --init --rm --name apache_cleanup -p '1080:1080' apache_cleanup
time curl localhost:1080/test -v
docker stop apache_cleanup
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.