@@ -321,6 +321,7 @@ static void incoming_request_handler(getdns_context *context,
321321 uint32_t qtype ;
322322 uint32_t qclass ;
323323 getdns_return_t r ;
324+ getdns_return_t * prev_r = (getdns_return_t * )userarg ;
324325 getdns_dict * header ;
325326 uint32_t n ;
326327 getdns_list * list ;
@@ -334,7 +335,6 @@ static void incoming_request_handler(getdns_context *context,
334335 uint32_t rr_type ;
335336
336337 (void )callback_type ;
337- (void )userarg ;
338338
339339 if (!(qext = getdns_dict_create_with_context (context )) ||
340340 !(msg = malloc (sizeof (dns_msg ))))
@@ -418,16 +418,22 @@ static void incoming_request_handler(getdns_context *context,
418418 stubby_getdns_strerror (r ));
419419
420420 else if ((r = getdns_general (context , qname_str , qtype ,
421- qext , msg , & transaction_id , request_cb )))
422- stubby_error ("Could not schedule query: %s" ,
423- stubby_getdns_strerror (r ));
424- else {
421+ qext , msg , & transaction_id , request_cb ))) {
422+ if (!prev_r || r != * prev_r
423+ || r != GETDNS_RETURN_NO_UPSTREAM_AVAILABLE )
424+ stubby_error ("Could not schedule query: %s" ,
425+ stubby_getdns_strerror (r ));
426+ } else {
425427 DEBUG_SERVER ("scheduled: %p %" PRIu64 " for %s %d\n" ,
426428 (void * )msg , transaction_id , qname_str , (int )qtype );
427429 getdns_dict_destroy (qext );
428430 free (qname_str );
431+ if (prev_r )
432+ * prev_r = r ;
429433 return ;
430434 }
435+ if (prev_r )
436+ * prev_r = r ;
431437error :
432438 if (qname_str )
433439 free (qname_str );
@@ -459,7 +465,7 @@ static void incoming_request_handler(getdns_context *context,
459465 getdns_dict_destroy (response );
460466}
461467
462- int server_listen (getdns_context * context , int validate_dnssec )
468+ int server_listen (getdns_context * context , void * userarg , int validate_dnssec )
463469{
464470 const getdns_list * listen_list ;
465471
@@ -469,7 +475,7 @@ int server_listen(getdns_context *context, int validate_dnssec)
469475 if ( !listen_list )
470476 return 0 ;
471477 if ( getdns_context_set_listen_addresses (
472- context , listen_list , NULL , incoming_request_handler ) ) {
478+ context , listen_list , userarg , incoming_request_handler ) ) {
473479 stubby_error ("error: Could not bind on given addresses: %s" , strerror (errno ));
474480 return 0 ;
475481 }
0 commit comments