]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Handle double timeout in udp_cancel_read test
authorOndřej Surý <ondrej@isc.org>
Tue, 11 Oct 2022 07:06:37 +0000 (09:06 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 11 Oct 2022 13:01:35 +0000 (15:01 +0200)
If sending took too long the isc_nm_read() could timeout twice, leading
to extra 'cread' counter in the udp_cancel_read test.  Increase the
cread counter only on ISC_R_EOF (canceled read) and deal with the
multiple ISC_R_TIMEOUTS gracefully.

tests/isc/udp_test.c

index 9644f7c0fa4088abd1a7e495a7bd10da93867ca2..c36074e3041f7dba039ead7ef47fc0bd13aeceaf 100644 (file)
@@ -702,15 +702,17 @@ udp_cancel_read_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
                isc_nmhandle_attach(handle, &readhandle);
                isc_nm_read(handle, udp_cancel_read_read_cb, cbarg);
 
-               /* Send */
-               isc_refcount_increment0(&active_csends);
-               isc_nmhandle_attach(handle, &sendhandle);
-               isc_nmhandle_setwritetimeout(handle, T_IDLE);
-               isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
-                           udp_cancel_read_send_cb, cbarg);
+               /* Send only once */
+               if (isc_refcount_increment0(&active_csends) == 0) {
+                       isc_nmhandle_attach(handle, &sendhandle);
+                       isc_nmhandle_setwritetimeout(handle, T_IDLE);
+                       isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
+                                   udp_cancel_read_send_cb, cbarg);
+               }
                break;
        case ISC_R_EOF:
                /* The read has been canceled */
+               atomic_fetch_add(&creads, 1);
                isc_loopmgr_shutdown(loopmgr);
                break;
        default:
@@ -719,8 +721,6 @@ udp_cancel_read_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
 
        isc_refcount_decrement(&active_creads);
 
-       atomic_fetch_add(&creads, 1);
-
        isc_nmhandle_detach(&handle);
 }
 
@@ -743,7 +743,7 @@ udp_cancel_read_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
 ISC_SETUP_TEST_IMPL(udp_cancel_read) {
        setup_test(state);
        expected_cconnects = 1;
-       expected_creads = 2;
+       expected_creads = 1;
        return (0);
 }