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/10/19 04:26:38 UTC

[Bug 4635] Bayes fails to initialize MySQL and PgSQL database

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





------- Additional Comments From jagerman@jagerman.com  2005-10-18 19:26 -------
I looked into this for another problem (as it turned out, completely unrelated,
and my own fault), and I don't think this is the proper change.  Basically, (as
I understand it) is_scan_available is meant to return 0 at that point to
indicate that no bayes scan is available - because there is no stored bayes data
for that user.  This is The Right Thing - with no bayes data, no bayes scan is
possible.  Even *with* your change, the subroutine will still return 0 once it
gets down to the min_spam/min_ham checks further in the subroutine.

When learning is enabled and SpamAssassin decides to learn from the message, it
doesn't check is_scan_available.  Instead, it will call tie_db_writable(), which
creates the user if needed, then inserts the data.

That said, I believe there *is* a problem here - if $self->_initialize_db(0) (at
Mail/SpamAssassin/BayesStore/SQL.pm, line 140) fails, ->untie_db() will be
called, which proceeds to call $self->{_dbh}->disconnect (the comment right
above this function is entirely misleading, if not completely wrong) - but that
means that if learning happens, BayesStore/SQL.pm has now connected to the
database twice instead of simply reusing the same connection (or potentially
much more than twice, if BayesStore is used multiple times without an ->untie_db()).

That problem can, I believe, be fixed by changing the return value here from 0
to -1 (BayesStore/SQL.pm, lines 1772-1773):

  # Do not create an entry for this user unless we were specifically asked to
  return 0 unless ($create_entry_p);

then, in tie_db_readonly, changing (lines 140-144) from:

  unless ($self->_initialize_db(0)) {
    dbg("bayes: unable to initialize database for ".$self->{_username}." user,
aborting!");
    $self->untie_db();
    return 0;
  }

to:

  unless (my $init = $self->_initialize_db(0)) {
    dbg("bayes: unable to initialize database for ".$self->{_username}." user,
aborting!");
    $self->untie_db();
    return 0;
  }
  elsif ($init == -1) {
    dbg("bayes: $self->{_username} has no data in database, aborting!");
    return 0;
  }

I'm not intimately familiar with all the innards of spam assassin, so hopefully
someone more experienced with it than I can tell me whether my understanding of
how this code works is correct or not.




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