From e61ba5865f801adc769df6967dc8ca9d6fa024b5 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 19 Dec 2024 14:22:54 +0000 Subject: [PATCH] Use a suitable response in tcp_connected() when initiating a read When 'ISC_R_TIMEDOUT' is received in 'tcp_recv()', it times out the oldest response in the active responses queue, and only after that it checks whether other active responses have also timed out. So when setting a timeout value for a read operation after a successful connection, it makes sense to take the timeout value from the oldest response in the active queue too, because, theoretically, the responses can have different timeout values, e.g. when the TCP dispatch is shared. Currently 'resp' is always NULL. Previously when connect and read timeouts were not separated in dispatch this affected only logging, but now since we are setting a new timeout after a successful connection, we need to choose a suitable response from the active queue. --- lib/dns/dispatch.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 53c8b4b8a4..12f3d9c5a2 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -1871,18 +1871,17 @@ tcp_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) { } } - if (ISC_LIST_EMPTY(disp->active)) { + /* Take the oldest active response. */ + resp = ISC_LIST_HEAD(disp->active); + if (resp == NULL) { /* All responses have been canceled */ disp->state = DNS_DISPATCHSTATE_CANCELED; } else if (eresult == ISC_R_SUCCESS) { disp->state = DNS_DISPATCHSTATE_CONNECTED; isc_nmhandle_attach(handle, &disp->handle); - if (resp != NULL) { - isc_nmhandle_cleartimeout(disp->handle); - if (resp->timeout != 0) { - isc_nmhandle_settimeout(disp->handle, - resp->timeout); - } + isc_nmhandle_cleartimeout(disp->handle); + if (resp->timeout != 0) { + isc_nmhandle_settimeout(disp->handle, resp->timeout); } tcp_startrecv(disp, resp); } else {