From 02c42a20b7cabcdd44ee8afdda888a521444258e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Tue, 11 Oct 2022 09:06:37 +0200 Subject: [PATCH] Handle double timeout in udp_cancel_read test 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 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/isc/udp_test.c b/tests/isc/udp_test.c index 9644f7c0fa..c36074e304 100644 --- a/tests/isc/udp_test.c +++ b/tests/isc/udp_test.c @@ -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); }