From b9b760c6e61931b16730d41e79385b10dcb5ac67 Mon Sep 17 00:00:00 2001
From: Marek Vavrusa <marek.vavrusa@nic.cz>
Date: Mon, 8 Jul 2013 13:43:58 +0200
Subject: [PATCH] Thread state should be checked after each request.

Otherwise it would finish all pending queries, some of which may have
connection already dropped. This usually isn't a problem, it just
presents a longer wait for the timeouts.
---
 src/knot/server/xfr-handler.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/knot/server/xfr-handler.c b/src/knot/server/xfr-handler.c
index d4eaccdd7..b82358796 100644
--- a/src/knot/server/xfr-handler.c
+++ b/src/knot/server/xfr-handler.c
@@ -1078,30 +1078,26 @@ int xfr_worker(dthread_t *thread)
 		fdset_it_t it;
 		fdset_begin(w->pool.fds, &it);
 		while(nfds > 0) {
-
-			/* Find data. */
 			knot_ns_xfr_t *rq = xfr_task_get(w, it.fd);
-			dbg_xfr_verb("xfr: worker=%p processing event on "
-			             "fd=%d data=%p.\n",
-			             w, it.fd, rq);
 			if (rq) {
-				/* Check task state. */
 				if (rq->flags & XFR_FLAG_CONNECTING) {
 					ret = xfr_task_process(w, rq, buf, buflen);
 				} else {
 					ret = xfr_process_event(w, rq);
 				}
 
+				/* Check task state. */
 				if (ret != KNOT_EOK) {
 					xfr_task_remove(w, it.fd);
 					--it.pos; /* Reset iterator */
 				}
 			}
 
-			/* Next fd. */
-			if (fdset_next(w->pool.fds, &it) < 0) {
+			/* Check for cancellation or next active fd. */
+			if (dt_is_cancelled(thread))
+				break;
+			if (fdset_next(w->pool.fds, &it) < 0)
 				break;
-			}
 		}
 
 		/* Sweep inactive. */
-- 
GitLab