From 5ebb51418d61f8d69234ee9bb9e6f7ea8051b7b9 Mon Sep 17 00:00:00 2001
From: Vsevolod Stakhov <vsevolod@rambler-co.ru>
Date: Mon, 14 Mar 2011 16:58:05 +0300
Subject: Race again.

---
 src/plugins/surbl.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c
index b79f21e94..ed7bc28fa 100644
--- a/src/plugins/surbl.c
+++ b/src/plugins/surbl.c
@@ -825,6 +825,7 @@ redirector_callback (gint fd, short what, void *arg)
 				msg_err ("write failed %s to %s", strerror (errno), param->redirector->name);
 				upstream_fail (&param->redirector->up, param->task->tv.tv_sec);
 				remove_normal_event (param->task->s, free_redirector_session, param);
+
 				param->task->save.saved--;
 				make_surbl_requests (param->url, param->task, param->suffix, FALSE);
 				if (param->task->save.saved == 0) {
@@ -841,6 +842,7 @@ redirector_callback (gint fd, short what, void *arg)
 					param->task->message_id, param->redirector->name);
 			upstream_fail (&param->redirector->up, param->task->tv.tv_sec);
 			remove_normal_event (param->task->s, free_redirector_session, param);
+
 			param->task->save.saved--;
 			make_surbl_requests (param->url, param->task, param->suffix, FALSE);
 			if (param->task->save.saved == 0) {
@@ -884,6 +886,9 @@ redirector_callback (gint fd, short what, void *arg)
 					parse_uri (param->url, memory_pool_strdup (param->task->task_pool, c), param->task->task_pool);
 				}
 			}
+			upstream_ok (&param->redirector->up, param->task->tv.tv_sec);
+			remove_normal_event (param->task->s, free_redirector_session, param);
+
 			param->task->save.saved--;
 			make_surbl_requests (param->url, param->task, param->suffix, FALSE);
 			if (param->task->save.saved == 0) {
@@ -891,13 +896,14 @@ redirector_callback (gint fd, short what, void *arg)
 				param->task->save.saved = 1;
 				process_filters (param->task);
 			}
-			upstream_ok (&param->redirector->up, param->task->tv.tv_sec);
-			remove_normal_event (param->task->s, free_redirector_session, param);
+
 		}
 		else {
 			msg_info ("<%s> reading redirector %s timed out, while waiting for read",
 					param->redirector->name, param->task->message_id);
 			upstream_fail (&param->redirector->up, param->task->tv.tv_sec);
+			remove_normal_event (param->task->s, free_redirector_session, param);
+
 			param->task->save.saved--;
 			make_surbl_requests (param->url, param->task, param->suffix, FALSE);
 			if (param->task->save.saved == 0) {
@@ -905,7 +911,6 @@ redirector_callback (gint fd, short what, void *arg)
 				param->task->save.saved = 1;
 				process_filters (param->task);
 			}
-			remove_normal_event (param->task->s, free_redirector_session, param);
 		}
 		break;
 	}
-- 
cgit v1.2.3