Adam Tkac 2bd245
--- bind-9.8.0-P4/lib/dns/request.c.test	2011-08-04 19:13:34.300999355 +0200
Adam Tkac 2bd245
+++ bind-9.8.0-P4/lib/dns/request.c	2011-08-04 19:37:40.347002723 +0200
Adam Tkac 2bd245
@@ -97,6 +97,7 @@ struct dns_request {
Adam Tkac 2bd245
 					   synchronously canceled */
Adam Tkac 2bd245
 #define DNS_REQUEST_F_TIMEDOUT 0x0008	/*%< canceled due to a timeout */
Adam Tkac 2bd245
 #define DNS_REQUEST_F_TCP 0x0010	/*%< This request used TCP */
Adam Tkac 2bd245
+#define DNS_REQUEST_F_RESPONSE 0x0020	/*%< We got response */
Adam Tkac 2bd245
 #define DNS_REQUEST_CANCELED(r) \
Adam Tkac 2bd245
 	(((r)->flags & DNS_REQUEST_F_CANCELED) != 0)
Adam Tkac 2bd245
 #define DNS_REQUEST_CONNECTING(r) \
Adam Tkac 2bd245
@@ -105,6 +106,8 @@ struct dns_request {
Adam Tkac 2bd245
 	(((r)->flags & DNS_REQUEST_F_SENDING) != 0)
Adam Tkac 2bd245
 #define DNS_REQUEST_TIMEDOUT(r) \
Adam Tkac 2bd245
 	(((r)->flags & DNS_REQUEST_F_TIMEDOUT) != 0)
Adam Tkac 2bd245
+#define DNS_REQUEST_RESPONSE(r) \
Adam Tkac 2bd245
+	(((r)->flags & DNS_REQUEST_F_RESPONSE) != 0)
Adam Tkac 2bd245
 
Adam Tkac 2bd245
 
Adam Tkac 2bd245
 /***
Adam Tkac 2bd245
@@ -1312,9 +1315,15 @@ req_senddone(isc_task_t *task, isc_event
Adam Tkac 2bd245
 
Adam Tkac 2bd245
 	if (DNS_REQUEST_CANCELED(request)) {
Adam Tkac 2bd245
 		/*
Adam Tkac 2bd245
-		 * Send delayed event.
Adam Tkac 2bd245
+		 * Response can arrive before we proccess
Adam Tkac 2bd245
+		 * req_senddone which means we received cancellation
Adam Tkac 2bd245
+		 * request from req_response(). If we successfully
Adam Tkac 2bd245
+		 * fetched response, send success. Otherwise
Adam Tkac 2bd245
+		 * indicate failure.
Adam Tkac 2bd245
 		 */
Adam Tkac 2bd245
-		if (DNS_REQUEST_TIMEDOUT(request))
Adam Tkac 2bd245
+		if (DNS_REQUEST_RESPONSE(request))
Adam Tkac 2bd245
+			send_if_done(request, ISC_R_SUCCESS);
Adam Tkac 2bd245
+		else if (DNS_REQUEST_TIMEDOUT(request))
Adam Tkac 2bd245
 			send_if_done(request, ISC_R_TIMEDOUT);
Adam Tkac 2bd245
 		else
Adam Tkac 2bd245
 			send_if_done(request, ISC_R_CANCELED);
Adam Tkac 2bd245
@@ -1367,6 +1376,8 @@ req_response(isc_task_t *task, isc_event
Adam Tkac 2bd245
 	/*
Adam Tkac 2bd245
 	 * Send completion event.
Adam Tkac 2bd245
 	 */
Adam Tkac 2bd245
+	if (result == ISC_R_SUCCESS)
Adam Tkac 2bd245
+		request->flags |= DNS_REQUEST_F_RESPONSE;
Adam Tkac 2bd245
 	send_if_done(request, result);
Adam Tkac 2bd245
 	UNLOCK(&request->requestmgr->locks[request->hash]);
Adam Tkac 2bd245
 }