Bug 6901 - untie db first to fix "bayes db version 0 is not able to be used, aborting!" problem
untie db first to fix "bayes db version 0 is not able to be used, aborting!" ...
Status: RESOLVED FIXED
Product: Spamassassin
Classification: Unclassified
Component: Learner
3.3.2
PC Linux
: P2 major
: 3.4.0
Assigned To: SpamAssassin Developer Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2013-01-31 01:10 UTC by Rob Mueller
Modified: 2013-02-28 15:24 UTC (History)
2 users (show)



Attachment Type Modified Status Actions Submitter/CLA Status
comitted diff patch None Mark Martinec [HasCLA]

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Mueller 2013-01-31 01:10:56 UTC
For the longest time, we've been seeing intermittent bayes db corruption with the error:

"bayes: bayes db version 0 is not able to be used, aborting!"

After a week of adding more and more debug statements and getting more and more confused, I finally concluded it had to be something weird in DB_File. I finally created a test case that reproduced it, which resulted in this bug.

https://rt.cpan.org/Ticket/Display.html?id=83060

I'm still calming down from my swearing session.

It seems to me the easiest solution is to add:

untie %{$self->{$db_var}};

Before any call to tie.

Annoyingly, there was code in tie_db_readonly to do this, but it's commented out and has been since the first commit.

    # untie %{$self->{$db_var}} if (tied %{$self->{$db_var}});

Adding a similar line to tie_db_writeable would be good as well.
Comment 1 Rob Mueller 2013-01-31 01:22:34 UTC
I've just applied this patch to my local DBM.pm module and will see in 24 hours how it's looking. I think this should fix it, but I'll update to confirm what I find.

---

--- DBM.pm      2013-01-30 20:20:43.000000000 -0500
+++ /usr/share/perl5/Mail/SpamAssassin/BayesStore/DBM.pm        2013-01-30 20:21:09.000000000 -0500
@@ -175,7 +175,7 @@
     my $db_var = 'db_'.$dbname;
     dbg("bayes: tie-ing to DB file R/O $name");

-    # untie %{$self->{$db_var}} if (tied %{$self->{$db_var}});
+    untie %{$self->{$db_var}};
     if (!tie %{$self->{$db_var}},$self->DBM_MODULE, $name, O_RDONLY,
                 (oct($main->{conf}->{bayes_file_mode}) & 0666))
     {
@@ -185,6 +185,7 @@
       # be writing to it; let the R/W api deal with that case.

       if ($dbname eq 'seen') {
+        untie %{$self->{$db_var}};
         tie %{$self->{$db_var}},$self->DBM_MODULE, $name, O_RDWR|O_CREAT,
                     (oct($main->{conf}->{bayes_file_mode}) & 0666)
           or goto failed_to_tie;
@@ -290,6 +291,7 @@
     ($self->DBM_MODULE eq 'DB_File') and
          Mail::SpamAssassin::Util::avoid_db_file_locking_bug ($name);

+    untie %{$self->{$db_var}};
     tie %{$self->{$db_var}},$self->DBM_MODULE, $name, O_RDWR|O_CREAT,
                 (oct($main->{conf}->{bayes_file_mode}) & 0666)
        or goto failed_to_tie;
Comment 2 Mark Martinec 2013-02-27 18:54:01 UTC
> I've just applied this patch to my local DBM.pm module and will see in 24
> hours how it's looking. I think this should fix it, but I'll update to
> confirm what I find.

According to perl documentation untie has no effect if the variable
is not tied, so your solution looks harmless, and if it avoids
the bug so much the better. Thanks!

trunk:
  Bug 6901: untie db first to fix "bayes db version 0 is not able
  to be used, aborting!" problem
Sending lib/Mail/SpamAssassin/BayesStore/DBM.pm
Committed revision 1450914.
Comment 3 Mark Martinec 2013-02-27 18:55:45 UTC
Created attachment 5135 [details]
comitted diff
Comment 4 Rob Mueller 2013-02-27 23:07:53 UTC
FYI I've been running with the patch for a few weeks now, and all the error messages are gone, so this definitely fixed the problem for us.
Comment 5 Mark Martinec 2013-02-28 15:24:08 UTC
Ok, let's consider this closed, thanks for investigating
and for reporting the tie issue to CPAN.