summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Pennock <pdp@exim.org>2011-02-21 00:11:32 -0500
committerPhil Pennock <pdp@exim.org>2011-02-21 00:13:18 -0500
commit29cfeb94e35eb8fe2b6f02fe9c9444edb251fd71 (patch)
tree287642bd0a2fada4e4ab79d13c7d619c52239947
parent332f5cf3ddb43e1a85d70039211e73aa1a753ebd (diff)
Improved spamd server selection.
Patch from Mark Zealey. Fixes bug 1056.
-rw-r--r--doc/doc-txt/ChangeLog3
-rw-r--r--doc/doc-txt/NewStuff3
-rw-r--r--src/src/spam.c35
3 files changed, 26 insertions, 15 deletions
diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index 1fd7bd3cf..1fb19caee 100644
--- a/doc/doc-txt/ChangeLog
+++ b/doc/doc-txt/ChangeLog
@@ -63,6 +63,9 @@ PP/10 Use sig_atomic_t for flags set from signal handlers.
PP/11 Bugzilla 1055: Update $message_linecount for maildir_tag.
Patch from Mark Zealey.
+PP/12 Bugzilla 1056: Improved spamd server selection.
+ Patch from Mark Zealey.
+
Exim version 4.74
-----------------
diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index 7ae550bb4..b940afe34 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -29,6 +29,9 @@ Version 4.75
in the same way as $message_size, to reflect the real number of lines,
including any header additions or removals from transport.
+ 5. When contacting a pool of SpamAssassin servers configured in spamd_address,
+ Exim now selects entries randomly, to better scale in a cluster setup.
+
Version 4.74
------------
diff --git a/src/src/spam.c b/src/src/spam.c
index ac9642028..55999a397 100644
--- a/src/src/spam.c
+++ b/src/src/spam.c
@@ -111,10 +111,8 @@ int spam(uschar **listptr) {
/* socket does not start with '/' -> network socket */
if (*spamd_address_work != '/') {
- time_t now = time(NULL);
int num_servers = 0;
- int current_server = 0;
- int start_server = 0;
+ int current_server;
uschar *address = NULL;
uschar *spamd_address_list_ptr = spamd_address_work;
uschar address_buffer[256];
@@ -126,6 +124,7 @@ int spam(uschar **listptr) {
address_buffer,
sizeof(address_buffer))) != NULL) {
+ /* Potential memory leak as we never free the store. */
spamd_address_container *this_spamd =
(spamd_address_container *)store_get(sizeof(spamd_address_container));
@@ -150,9 +149,10 @@ int spam(uschar **listptr) {
return DEFER;
};
- current_server = start_server = (int)now % num_servers;
+ while ( num_servers > 0 ) {
- while (1) {
+ /* Randomly pick a server to try */
+ current_server = random_number( num_servers );
debug_printf("trying server %s, port %u\n",
spamd_address_vector[current_server]->tcp_addr,
@@ -180,16 +180,21 @@ int spam(uschar **listptr) {
spamd_address_vector[current_server]->tcp_addr,
spamd_address_vector[current_server]->tcp_port,
strerror(errno));
- current_server++;
- if (current_server >= num_servers)
- current_server = 0;
- if (current_server == start_server) {
- log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
- (void)fclose(mbox_file);
- (void)close(spamd_sock);
- return DEFER;
- };
- };
+
+ (void)close(spamd_sock);
+
+ /* Remove the server from the list. XXX We should free the memory */
+ num_servers--;
+ int i;
+ for( i = current_server; i < num_servers; i++ )
+ spamd_address_vector[i] = spamd_address_vector[i+1];
+ }
+
+ if ( num_servers == 0 ) {
+ log_write(0, LOG_MAIN|LOG_PANIC, "spam acl condition: all spamd servers failed");
+ (void)fclose(mbox_file);
+ return DEFER;
+ }
}
else {