如何在 Apache httpd 2.4 启动和重新加载期间调试 mod_perl 编译错误?

如何在 Apache httpd 2.4 启动和重新加载期间调试 mod_perl 编译错误?

我正在运行 Ubuntu 16.04 LTS,带有 httpd 2.4 和 mod_perl2 来托管PerlAuthenHandler对于某些 Web 应用。之前版本是 14.04 LTS,几周前进行了升级。

这通常有效,但有时,尤其是在重新加载和重新启动 httpd 时,mod_perl 会在编译我的处理程序时遇到问题,从而导致错误,因此虽然 httpd 仍在运行,但 mod_perl 处于无法再处理任何内容的状态。由于 mod_perl 在运行时使用多个解释器,其中一些解释器可能在任何请求中首次使用,因此即使没有重新加载/重新启动 httpd 服务本身,也可能会进行编译。但与每天早上至少重新加载一次 httpd(由于日志轮换)相比,这种情况似乎并不常见。

这些编译错误并非总是发生,实际上只是偶尔发生。处理程序可能运行良好几天,但在重新加载日志轮换时它会停止工作。或者重新启动 httpd 也是一样:在大多数情况下,这也能正常工作,但有时在这种重新启动过程中 mod_perl 中已经出现编译错误。在大多数情况下,这些错误会在之后再次重新启动后消失。

这些错误不会直接发生在我自己的代码中,而只会发生在我正在use使用的库中,因此是在编译期间。这些库不是使用 CPAN 或类似工具安装的,而是由我的发行版的包管理器安装的,这应该是最“正确”和最兼容的做法。当然,这些库和我自己的代码在工作/不工作周期之间不会发生变化,安装的任何东西实际上都没有任何区别,甚至自动安全更新或类似的东西也没有区别。它似乎只是因为某种原因在某一天停止工作。

错误本身从来不是运行时问题,而实际上总是与源代码编译有关,例如 Perl 代码中的语法错误等。当然,错误并不总是相同的,尽管有些错误似乎比其他错误更频繁地发生。

示例 1:

[Mon Jun 05 06:25:23.818862 2017] [core:notice] [pid 21652:tid 139994496042880] AH00094: Command line: '/usr/sbin/apache2'
String found where operator expected at /usr/share/perl/5.22/Tie/Hash.pm line 25, near "croak "$pkg must define either a TIEHASH() or a new() method""
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/Tie/Hash.pm line 33, near "croak "$pkg doesn't define a TIEHASH method""
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/Tie/Hash.pm line 39, near "croak "$pkg doesn't define an EXISTS method""
  (Do you need to predeclare croak?)
[Mon Jun 05 16:14:21.233643 2017] [mpm_event:notice] [pid 21652:tid 139994496042880] AH00491: caught SIGTERM, shutting down

示例 2:

[Tue Jun 06 06:25:23.200424 2017] [core:notice] [pid 7051:tid 139688717936512] AH00094: Command line: '/usr/sbin/apache2'
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 199, near "croak 'Usage: ($fh, $name) = _gettemp($template, OPTIONS);'"
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 221, near "carp "File::Temp::_gettemp: template must not be a reference""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 228, near "carp "File::Temp::_gettemp: Must have even number of options""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 482, near "croak 'Usage: _replace_XX($template, $ignore)'"
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 808, near "croak 'Usage:  _deferred_unlink($fh, $fname, $isdir)'"
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 835, near "carp "Request to remove directory $fname could not be completed since it does not exist!\n""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 848, near "carp "Request to remove file $fname could not be completed since it is not there!\n""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 993, near "croak "'tempfile' can't be called as a method""
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 1080, near "croak "Error in tempfile() using template $template: $errstr""
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl/5.22/File/Temp.pm line 1111, near "croak "Error unlinking file $path using unlink0""
[Tue Jun 06 07:54:18.220486 2017] [mpm_event:notice] [pid 7051:tid 139688717936512] AH00491: caught SIGTERM, shutting down

示例 3:

[Tue Jun 06 11:17:40.789534 2017] [core:notice] [pid 4498:tid 139925979752320] AH00094: Command line: '/usr/sbin/apache2'
String found where operator expected at /usr/share/perl/5.22/SelectSaver.pm line 10, near "croak 'usage: SelectSaver->new( [FILEHANDLE] )'"
  (Do you need to predeclare croak?)
[Tue Jun 06 11:25:25.344061 2017] [mpm_event:notice] [pid 4498:tid 139925979752320] AH00491: caught SIGTERM, shutting down

示例 4:

[Tue Jun 06 12:09:54.763670 2017] [core:notice] [pid 16855:tid 139853164218240] AH00094: Command line: '/usr/sbin/apache2'
String found where operator expected at (eval 10) line 2, near "croak 'usage: $io->getline()'"
  (Do you need to predeclare croak?)
String found where operator expected at (eval 10) line 8, near "croak 'usage: $io->getlines()'"
  (Do you need to predeclare croak?)
String found where operator expected at (eval 10) line 10, near "croak 'Can\'t call $io->getlines in a scalar context, use $io->getline'"
  (Do you need to predeclare croak?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 400, near "carp "Invalid -import value \"$parms{-import}\" was ignored.""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 446, near "carp "Comment character must be unique.""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 451, near "carp "Illegal comment character.""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 461, near "carp "Illegal value for -allowedcommentchars.""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 482, near "carp "Unknown named parameter $k=>$v""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 768, near "carp "Unhandled data structure in $ref, cannot _deepcopy()""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 1273, near "carp "Failed to open $self->{cf}: $!""
  (Do you need to predeclare carp?)
String found where operator expected at /usr/share/perl5/Config/IniFiles.pm line 1769, near "carp "Unable to rename temp config file ($new_file) to ${filename}: $!""
  (Do you need to predeclare carp?)
[Tue Jun 06 12:10:23.827500 2017] [mpm_event:notice] [pid 16855:tid 139853164218240] AH00491: caught SIGTERM, shutting down

有时错误甚至声称以下代码中的第 4 行parent.pm是错误的,因为$VERSION未定义:

package parent;
use strict;
use vars qw($VERSION);
$VERSION = '0.232';

sub import {

所以最后,它看起来像是由于 mod_perl 编译器中的内部错误或某些错误的内部状态等导致的一些随机的东西。

关于如何调试并找到问题根源,您有什么想法吗?或者您知道问题可能已经存在吗?

相关内容