Bug 5985 - Client.pm - 'message: error reading: Bad file descriptor at lib/Mail/SpamAssassin/Message/Node.pm line 279'
Summary: Client.pm - 'message: error reading: Bad file descriptor at lib/Mail/SpamAssa...
Status: RESOLVED FIXED
Alias: None
Product: Spamassassin
Classification: Unclassified
Component: Libraries (show other bugs)
Version: SVN Trunk (Latest Devel Version)
Hardware: Other Linux
: P5 minor
Target Milestone: 3.3.0
Assignee: SpamAssassin Developer Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-23 02:58 UTC by Justin Mason
Modified: 2009-08-04 08:17 UTC (History)
1 user (show)



Attachment Type Modified Status Actions Submitter/CLA Status

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Mason 2008-09-23 02:58:46 UTC
This message appears on a few linux systems I have here, during mass-checks and in the "make test" output.  I've narrowed this bug down to a small testcase:

: jm 175...; ./spamassassin.raw -C tst.cf -L -t < in.txt > /dev/null
[3838] warn: config: could not find site rules directory
[3838] warn: rules: failed to run MIME_HTML_ONLY test, skipping:
[3838] warn:  (message: error reading: Bad file descriptor at lib/Mail/SpamAssassin/Message/Node.pm line 279, <$tmpfile> line 1.
[3838] warn: )

tst.cf:---------------------------------------------------------------------

loadplugin Mail::SpamAssassin::Plugin::Check
loadplugin Mail::SpamAssassin::Plugin::MIMEEval
body MIME_HTML_ONLY eval:check_for_mime_html_only()

in.txt:---------------------------------------------------------------------

Content-Type: multipart/mixed; boundary="x7"
MIME-Version: 1.0

--x7
Content-Type: text/html

a

--x7
Content-Type: application/pdf

b
--x7--

---------------------------------------------------------------------------
Comment 1 Justin Mason 2008-09-23 03:22:44 UTC
fine on Solaris x86 with perl 5.8.6.
fine on MacOS X with perl 5.8.8.
bug happens with Linux (Ubuntu gutsy), perl 5.8.8.
bug happens with Linux (Ubuntu hardy 8.04.1), perl 5.8.8.

looks like a platform-specific perl bug. I also can't repro it with this test script: http://taint.org/x/2008/bug5985scr , despite the "strace" output looking pretty similar.

This is a hacky workaround, checking eof() if an error condition is indicated:

: jm 65...; svn commit -m "bug 5985: avoid spurious 'message: error reading: Bad file descriptor' error during normal use" lib
Sending        lib/Mail/SpamAssassin/Message/Node.pm
Transmitting file data .
Committed revision 698119.

However, maybe we should just skip the error check entirely; this workaround adds an additional read() syscall that is unnecessary, and may just hide "real" bugs anyway, since hte doco says that eof() returns 1 if the FH is not open, too.

feel free to try to find a better fix... ;)
Comment 2 Mark Martinec 2008-09-23 06:20:43 UTC
> fine on Solaris x86 with perl 5.8.6.
> fine on MacOS X with perl 5.8.8.
> bug happens with Linux (Ubuntu gutsy), perl 5.8.8.
> bug happens with Linux (Ubuntu hardy 8.04.1), perl 5.8.8.
> 
> looks like a platform-specific perl bug. I also can't repro it with this test
> script: http://taint.org/x/2008/bug5985scr , despite the "strace" output
> looking pretty similar.

A Perl bug on Linux, see:

  http://rt.perl.org/rt3//Public/Bug/Display.html?id=39060

Some Linux distributions set env. var. PERLIO="stdio".
Dropping it (unset PERLIO, or setting it to "") avoids the bug.
Comment 3 Mark Martinec 2008-09-25 08:45:42 UTC
Sending        lib/Mail/SpamAssassin/Message/Node.pm
Sending        lib/Mail/SpamAssassin/Message.pm
Committed revision 699006.

Message.pm and Message/Node.pm: replace line-by-line reading by
sysread + split, thus avoiding a Perl i/o bug on some platforms
( http://rt.perl.org/rt3//Public/Bug/Display.html?id=39060 ,
SA Bug 5985), while also providing a little speedup (10..25%)
on reading a message.
Comment 4 Daryl C. W. O'Shea 2008-10-01 19:37:24 UTC
Looks like M::SA::AI has the same issue in a few spots.

status:  14% ham: 11     spam: 465    date: 2008-08-04   now: 2008-10-01 05:11:00
status:  15% ham: 12     spam: 498    date: 2008-08-04   now: 2008-10-01 05:11:01
error reading: Bad file descriptor at /home/dos/sa-mass-check/nightly_mass_check/masses/../blib/lib/Mail/SpamAssassin/ArchiveIterator.pm line 380, <INPUT> line 2783.


There are probably other areas where the same thing is done (sa-learn perhaps).
Comment 5 Mark Martinec 2008-10-02 01:47:42 UTC
> lib/Mail/SpamAssassin/ArchiveIterator.pm line 380, <INPUT> line 2783.
> There are probably other areas where the same thing is done (sa-learn perhaps).

Do you have the environment variable PERLIO explicitly set?
To a non-default perl setting? If yes, could you please unset it
and see if ArchiveIterator.pm still hits that perl bug.
Comment 6 Daryl C. W. O'Shea 2008-10-06 13:51:07 UTC
No, I do not.  Stock Fedora Core 6 Perl 5.8.8.
Comment 7 Mark Martinec 2008-10-07 10:51:45 UTC
Committed revision 702559:
  Bug 5985: avoid Perl I/O bug by replacing line-by-line reading
  with read() where suitable, or play down the EBADF status in
  other places and only report it as dbg instead of a die.
  Also localized a couple of file handles where I came across them.
Comment 8 Justin Mason 2008-10-08 01:37:24 UTC
(In reply to comment #7)
> Committed revision 702559:
>   Bug 5985: avoid Perl I/O bug by replacing line-by-line reading
>   with read() where suitable, or play down the EBADF status in
>   other places and only report it as dbg instead of a die.
>   Also localized a couple of file handles where I came across them.

will that fix Daryl's bug, do you think?

(asking because I think I may be running into it sporadically -- although I haven't been able to spot a mass-check where it's occurred for me recently.)
Comment 9 Mark Martinec 2008-10-08 03:33:35 UTC
> will that fix Daryl's bug, do you think?

I believe it does. The read() is not prone to this perl bug
and as a bonus is even faster where we can afford reading
in chunks instead of line-by-line (e.g. when the whole file
is intended to end up in memory anyway, or when copying it
to another file). The remaining cases of line-by-line reads
now report EBADF only at a dbg level.

I did the missed cases in sa-compile.raw and sa-learn.raw today,
revision 702797. The only module still without this playing down
of severity is Client.pm.

I opened a new perlbug [perl #59550], this time against perl 5.10 and
as a general case, not as a missing NL in the last line [perl #39060].
Still waiting for some response.
 
> (asking because I think I may be running into it sporadically -- although I
> haven't been able to spot a mass-check where it's occurred for me recently.)

Still after my yesterday's check-in?
Comment 10 Justin Mason 2008-10-08 03:38:58 UTC
(In reply to comment #9)
> > (asking because I think I may be running into it sporadically -- although I
> > haven't been able to spot a mass-check where it's occurred for me recently.)
> 
> Still after my yesterday's check-in?

no, it was at least a week ago.
Comment 11 Daryl C. W. O'Shea 2008-10-09 15:28:58 UTC
(In reply to comment #8)
> will that fix Daryl's bug, do you think?

Yes, this fixed the issue I was having.  Thanks Mark!

I'll leave this open since there's still Client.pm to take care of.
Comment 12 Mark Martinec 2009-06-30 16:16:36 UTC
> Yes, this fixed the issue I was having.  Thanks Mark!
> 
> I'll leave this open since there's still Client.pm to take care of.

Ok, I'll deal with it after the alpha release.

Btw, few weeks ago I got a report that the Perl I/O bug
is finally fixed in version 10, so the fix will probably
appear with the next Perl release.
Comment 13 Mark Martinec 2009-07-10 17:42:31 UTC
> > I'll leave this open since there's still Client.pm to take care of.
> Ok, I'll deal with it after the alpha release.

  Bug 5985 - Client.pm: deal gracefully with a Perl I/O bug which may
  return status EBADF at eof; add: use strict; use warnings; use re 'taint'
Sending        lib/Mail/SpamAssassin/Client.pm
Committed revision 793156.


Btw, is there any test for this module? Wouldn't hurt.
Comment 14 Mark Martinec 2009-08-04 08:17:24 UTC
> Btw, is there any test for this module? Wouldn't hurt.

Replying to myself: yes there is, it's the spamd_client.t,
and it passes all the tests on my host (perl 5.10.0).
Closing.