Possible deadlock and solution

Gyepi SAM gyepi at praxis-sw.com
Fri Sep 27 17:04:10 CEST 2002


I think we have the possibility of deadlock between instances of bogofilter called with the -S and -N flags,
which correspond, respectively, to one of these two calls:

   register_words(STDIN_FILENO, &good_list, &spam_list);
   register_words(STDIN_FILENO, &spam_list, &good_list);

Since register_words locks the list databases sequentially, in argument order,
we could have a situation where an instance of bogofilter -S will deadlock with
an instance of bogofilter -N if both instances successfully lock the first database
on their respective argument lists before attempting to lock the second databases. 

The solution:

Ensure that register_words always locks the databases in the same order by
1. Changing the declaration of register_words from

  void register_words(int fd, wordlist_t *list, wordlist_t *other);

to

  void register_words(int fd, wordlist_t *good, wordlist_t *bad, int transfer_order);

 
2. Changing the code in register_words(...) to use the transfer_order argument to determine 
   which way to transfer the word count. Obviously, we only look at the flag when both list arguments are non NULL.

I have made, other, unrelated, changes to bogofilter.c which will actually make this easier
to code, so I'll write the code.

-Gyepi



More information about the bogofilter-dev mailing list