You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@spamassassin.apache.org by bu...@bugzilla.spamassassin.org on 2005/05/26 21:24:20 UTC

[Bug 4370] New: Failed exec in forked helper process continues its miserable life

http://bugzilla.spamassassin.org/show_bug.cgi?id=4370

           Summary: Failed exec in forked helper process continues its
                    miserable life
           Product: Spamassassin
           Version: SVN Trunk (Latest Devel Version)
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Libraries
        AssignedTo: dev@spamassassin.apache.org
        ReportedBy: Mark.Martinec@ijs.si


The Util.pm module does: 
  exec @cmdline; die "util: exec failed: $!"; 
in a forked process ready to become an external application. 
 
The problem occurs if exec fails (e.g. pyzor is too strongly 
protected). In that case the die is supposed to terminate 
the spawned process, yet it seems to be intercepted by some 
higher-level eval, which leads to a horror situation where 
both the parent and its forked copy try to continue processing 
the same mail and to communicate with its environment, stepping 
on each other's toes. 
 
In case of amavisd-new this shows as unexplainable secondary 
error reports, failed writes to a MTA socket or Berkeley db locker 
problems. I can imagine the situation is bad in spamd setup as well, 
although I don't know how it manifests itself. 
 
Even if eval were avoided and let 'die' do its job, this is still 
not good enough, as the Perl END and destructor processing by a 
spawned process may attempt to cleanup what is still needed 
by a parent process - and in fact this was demonstrated to 
still cause trouble in amavisd-new, and likely in spamd as well. 
 
The solution that is known to work properly is: 
  exec ... 
  # log error in $! 
  POSIX::_exit(1);  # avoid END and destructor processing 
  kill('KILL',$$);  # still kicking? die! 
 
(the POSIX::_exit is suggested by the perlfunc man page 
 at the exit() entry) 
 
  Mark



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

[Bug 4370] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


jm@jmason.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|Undefined                   |3.1.0




------- Additional Comments From jm@jmason.org  2005-08-05 10:48 -------
aiming at 3.1.0



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

[Bug 4370] [review] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370





------- Additional Comments From parkerm@pobox.com  2005-08-10 20:39 -------
+1



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

[Bug 4370] [review] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370





------- Additional Comments From duncf@debian.org  2005-08-10 20:41 -------
+1



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

[Bug 4370] [review] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


duncf@debian.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |spamassassin@dostech.ca




------- Additional Comments From duncf@debian.org  2005-08-27 17:45 -------
*** Bug 4476 has been marked as a duplicate of this bug. ***



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

[Bug 4370] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


jm@jmason.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From jm@jmason.org  2005-06-14 23:14 -------
thanks Mark -- applied.



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

[Bug 4370] [review] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


parkerm@pobox.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dev@spamassassin.apache.org






------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

[Bug 4370] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


jm@jmason.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|dev@spamassassin.apache.org |jm@jmason.org
             Status|REOPENED                    |ASSIGNED




------- Additional Comments From jm@jmason.org  2005-08-10 20:01 -------
Created an attachment (id=3071)
 --> (http://bugzilla.spamassassin.org/attachment.cgi?id=3071&action=view)
Util.pm patch




------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

[Bug 4370] [review] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


jm@jmason.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED




------- Additional Comments From jm@jmason.org  2005-08-10 20:52 -------
that was quick! r231387.



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

[Bug 4370] Failed exec in forked helper process continues its miserable life

Posted by bu...@bugzilla.spamassassin.org.
http://bugzilla.spamassassin.org/show_bug.cgi?id=4370


Mark.Martinec@ijs.si changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Additional Comments From Mark.Martinec@ijs.si  2005-08-05 07:20 -------
Justin, thanks for fixing the original problem. I'm reopening this bug 
because I discovered another code path which can still (today's CVS) 
produce the originally reported problem (runaway cloned process). 
Because the problem is in the same routine and is actually the same 
as the originally posted, I decided to re-open this old bug 
instead of creating a new report. 
 
Namely, apart from exec failing in Util::helper_app_pipe_open_unix, 
there are other failure modes possible in the forked process. 
In my new case it was a failure to open a temporary file 
(it happened because I had misconfigured directory protections). 
 
Here is a debug output, note the reported PID and the continuing 
of the process 90619: 
 
[90359] dbg: info: entering helper-app run mode 
[90359] dbg: dcc: opening pipe: /usr/local/bin/dccproc 
  -H -R < /var/amavis/tmp/.spamassassin90359CP4p6otmp 
[90619] dbg: util: setuid: ruid=110 euid=110 
[90619] dbg: info: leaving helper-app run mode dcc: check failed: 
  util: cannot open /var/amavis/tmp/.spamassassin90359CP4p6otmp: 
  Permission denied 
  at /usr/local/lib/perl5/site_perl/5.8.7/ 
     Mail/SpamAssassin/Util.pm line 1246. 
[90619] dbg: uridnsbl: select found 1 socks ready 
 
So the following open failed: 
  # acceptable to die() here, calling code catches it 
  open STDIN, "<$stdinfile" or die "util: cannot open $stdinfile: $!"; 
 
and instead of the cloned process going away, the die was caught by 
some eval and the cloned process continued its life pretending to be 
a genuine main SA process. 
 
In summary: any possible 'die' in that forked child process must be 
captured within that same routine, and must lead to the same POSIX::_exit(1) 
call at the end of that routine. 
 
As a sidenote, I should say that this time my life was saved (ok, the 
troubleshooting time reduced) by a safety net that is now built into 
amavisd-new around its call to SA. You might be interested in providing 
a similar safety net in spamd, just in case: 
 
(simplified, but essentially the:) 
 
  my($saved_pid) = $$; 
  $mail_obj = $spamassassin_obj->parse(\@lines); 
  $per_msg_status = $spamassassin_obj->check($mail_obj); 
  if ($$ != $saved_pid) { 
    eval { do_log(-2,"PANIC, SA produced a clone process ". 
                     "of [$saved_pid], TERMINATING CLONE [$$]") }; 
    POSIX::_exit(1);  # avoid END and destructor processing 
  } 
 
Mark 



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.