From 8ea2cd786448cd35d2311718eed4a2db024a68e8 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Mon, 8 Feb 2021 15:27:38 -0800 Subject: [PATCH] update the socket result correctly in tls_call_connect_cb(), we want to update the result for the TLS socket. however, in some error conditions on connect, the handle we're passing is for the TCP socket instead. this was causing the wrong socket's result code to be updated, and the thread that was waiting for the result to be updated never woke up. (note: while the fix in this commit causes doh_test to stop deadlocking, I'm not sure whether I've actually fixed the bug. in other places, we create a new 'tlshandle' to pass into tls_call_connect_cb(). perhaps we should be doing that in all cases?) incidentally, I also renamed tls_connect_cb() to tcp_connected(), because the handle passed in is for the TCP socket, and I kept being confused by the name having "tls" in it. --- lib/isc/netmgr/tlsstream.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/isc/netmgr/tlsstream.c b/lib/isc/netmgr/tlsstream.c index 37d6ce8140..795f447bf0 100644 --- a/lib/isc/netmgr/tlsstream.c +++ b/lib/isc/netmgr/tlsstream.c @@ -96,8 +96,7 @@ tls_call_connect_cb(isc_nmsocket_t *sock, isc_nmhandle_t *handle, return; } sock->connect_cb(handle, result, sock->connect_cbarg); - if (!sock->tlsstream.server) - update_result(handle->sock, result); + update_result(sock, result); if (result != ISC_R_SUCCESS) { isc__nmsocket_clearcb(handle->sock); } @@ -121,18 +120,6 @@ tls_senddone(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) { isc_mem_put(handle->sock->mgr->mctx, send_req, sizeof(*send_req)); sock->tlsstream.nsending--; - /*if (eresult != ISC_R_SUCCESS && - (sock->tlsstream.state == TLS_INIT || - sock->tlsstream.state == TLS_HANDSHAKE)) - { - isc_nmhandle_t *tlshandle = isc__nmhandle_get(sock, NULL, NULL); - printf("eresult: %d\n", eresult); - tls_call_connect_cb(sock, tlshandle, eresult); - isc_nmhandle_detach(&tlshandle); - isc__nmsocket_detach(&sock); - return; - }*/ - async_tls_do_bio(sock); isc__nmsocket_detach(&sock); @@ -839,7 +826,7 @@ isc_nm_tlsconnect(isc_nm_t *mgr, isc_nmiface_t *local, isc_nmiface_t *peer, } static void -tls_connect_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { +tcp_connected(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { isc_nmsocket_t *tlssock = (isc_nmsocket_t *)cbarg; REQUIRE(VALID_NMSOCK(tlssock)); @@ -897,7 +884,7 @@ isc__nm_async_tlsconnect(isc__networker_t *worker, isc__netievent_t *ev0) { * passed to it. */ (void)isc_nm_tcpconnect(worker->mgr, (isc_nmiface_t *)&ievent->local, - (isc_nmiface_t *)&ievent->peer, tls_connect_cb, + (isc_nmiface_t *)&ievent->peer, tcp_connected, tlssock, tlssock->connect_timeout, 0); return;