[Apache::DBI] [PATCH] use PerlChildExitHandler to properly disconnect
am 13.03.2008 02:40:38 von Alex Hunsaker------=_Part_8187_2566109.1205372438852
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
This Patch fixes annoying log messages (notably with postgresql, but
others may apply) because Apache::DBI fails to disconnect properly at
exit time.
(it stops the buggers below from filling my logs...)
LOG: unexpected EOF on client connection
LOG: could not receive data from client: Connection reset by peer
Note the first hunk *might* be a bug fix as under MP2
Apache->can('push_handlers') returns false.
It does not look (unless im missing something) like the
PerlCleanupHandler for AutoCommit rollback ever got registered...
(Patch attached as well in case white space damage occurs)
applies cleanly against 1.05/1.06
diff -x '*~' -ruN Apache-DBI-1.05.orig/lib/Apache/DBI.pm
Apache-DBI-1.05/lib/Apache/DBI.pm
--- Apache-DBI-1.05.orig/lib/Apache/DBI.pm 2006-11-03 23:17:44.000000000 -0700
+++ Apache-DBI-1.05/lib/Apache/DBI.pm 2008-03-12 17:38:37.455592048 -0600
@@ -137,7 +137,7 @@
# script has finished if AutoCommit is off. however, cleanup can only
# be determined at end of handle life as begin_work may have been called
# to temporarily turn off AutoCommit.
- if (!$Rollback{$Idx} and Apache->can('push_handlers')) {
+ if (!$Rollback{$Idx} and (Apache->can('push_handlers') || MP2)) {
debug(2, "$prefix push PerlCleanupHandler");
if (MP2) {
my $s = Apache2::ServerUtil->server;
@@ -151,6 +151,17 @@
$Rollback{$Idx} = 1;
}
+ if (Apache->can('push_handlers') || MP2) {
+ debug(2, "$prefix push PerlChildExitHandler");
+ if (MP2) {
+ my $s = Apache2::ServerUtil->server;
+ $s->push_handlers("PerlChildExitHandler", sub {
child_disconnect($Idx) });
+ }
+ else {
+ Apache->push_handlers("PerlChildExitHandler", sub {
child_disconnect($Idx) });
+ }
+ }
+
# do we need to ping the database ?
$PingTimeOut{$dsn} = 0 unless $PingTimeOut{$dsn};
$LastPingTime{$dsn} = 0 unless $LastPingTime{$dsn};
@@ -236,6 +247,26 @@
1;
}
+sub child_disconnect {
+ my $Idx = shift;
+
+ my $prefix = "$$ Apache::DBI ";
+ debug(2, "$prefix PerlChildExitHandler");
+
+ if ($Connected{$Idx}) {
+ cleanup($Idx);
+
+ {
+ package Apache::DBI::db;
+ eval { $Connected{$Idx}->SUPER::disconnect(); };
+ delete $Connected{$Idx}
+ }
+ debug(2, "$prefix PerlChildExitHandler disconnect for '$Idx'");
+ }
+
+ 1;
+}
+
# Store the default start state of each dbh in the handle
# Note: This uses private_Apache_DBI hash ref to store it in the handle itself
my @attrs = qw(
------=_Part_8187_2566109.1205372438852
Content-Type: application/octet-stream; name=apache_dbi_exithandler.patch
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fdqjhn9t0
Content-Disposition: attachment; filename=apache_dbi_exithandler.patch
ZGlmZiAteCAnKn4nIC1ydU4gQXBhY2hlLURCSS0xLjA1Lm9yaWcvbGliL0Fw YWNoZS9EQkkucG0g
QXBhY2hlLURCSS0xLjA1L2xpYi9BcGFjaGUvREJJLnBtCi0tLSBBcGFjaGUt REJJLTEuMDUub3Jp
Zy9saWIvQXBhY2hlL0RCSS5wbQkyMDA2LTExLTAzIDIzOjE3OjQ0LjAwMDAw MDAwMCAtMDcwMAor
KysgQXBhY2hlLURCSS0xLjA1L2xpYi9BcGFjaGUvREJJLnBtCTIwMDgtMDMt MTIgMTc6Mzg6Mzcu
NDU1NTkyMDQ4IC0wNjAwCkBAIC0xMzcsNyArMTM3LDcgQEAKICAgICAjIHNj cmlwdCBoYXMgZmlu
aXNoZWQgaWYgQXV0b0NvbW1pdCBpcyBvZmYuICBob3dldmVyLCBjbGVhbnVw IGNhbiBvbmx5CiAg
ICAgIyBiZSBkZXRlcm1pbmVkIGF0IGVuZCBvZiBoYW5kbGUgbGlmZSBhcyBi ZWdpbl93b3JrIG1h
eSBoYXZlIGJlZW4gY2FsbGVkCiAgICAgIyB0byB0ZW1wb3JhcmlseSB0dXJu IG9mZiBBdXRvQ29t
bWl0LgotICAgIGlmICghJ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QaW5nVGltZXskZHNu fSA9IDAgdW5sZXNz
ICRMYXN0UGluZ1RpbWV7JGRzbn07CkBAIC0yMzYsNiArMjQ3LDI2IEBACiAg ICAgMTsKIH0KIAor
c3ViIGNoaWxkX2Rpc2Nvbm5lY3QgeworICAgIG15ICRJZHggPSBzaGlmdDsK KyAgICAKKyAgICBt
eSAkcHJlZml4ID0gIiQkIEFwYWNoZTo6REJJICAgICAgICAgICAgIjsKKyAg ICBkZWJ1ZygyLCAi
JHByZWZpeCBQZXJsQ2hpbGRFeGl0SGFuZGxlciIpOworCisgICAgaWYgKCRD b25uZWN0ZWR7JElk
eH0pIHsKKyAgICAgICAgY2xlYW51cCgkSWR4KTsKKworICAgICAgICB7Cisg ICAgICAgICAgICBw
YWNrYWdlIEFwYWNoZTo6REJJOjpkYjsKKyAgICAgICAgICAgIGV2YWwgeyAk Q29ubmVjdGVkeyRJ
ZHh9LT5TVVBFUjo6ZGlzY29ubmVjdCgpOyB9OworICAgICAgICAgICAgZGVs ZXRlICRDb25uZWN0
ZWR7JElkeH0KKyAgICAgICAgfQorICAgICAgICBkZWJ1ZygyLCAiJHByZWZp eCBQZXJsQ2hpbGRF
eGl0SGFuZGxlciBkaXNjb25uZWN0IGZvciAnJElkeCciKTsKKyAgICB9CisK KyAgICAxOworfQor
CiAjIFN0b3JlIHRoZSBkZWZhdWx0IHN0YXJ0IHN0YXRlIG9mIGVhY2ggZGJo IGluIHRoZSBoYW5k
bGUKICMgTm90ZTogVGhpcyB1c2VzIHByaXZhdGVfQXBhY2hlX0RCSSBoYXNo IHJlZiB0byBzdG9y
ZSBpdCBpbiB0aGUgaGFuZGxlIGl0c2VsZgogbXkgQGF0dHJzID0gcXcoCg==
------=_Part_8187_2566109.1205372438852--