]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Always call TCP connect callback from within a worker context
authorArtem Boldariev <artem@boldariev.com>
Fri, 23 Apr 2021 14:50:04 +0000 (17:50 +0300)
committerArtem Boldariev <artem@boldariev.com>
Fri, 7 May 2021 12:47:24 +0000 (15:47 +0300)
This change ensures that a TCP connect callback is called from within
the context of a worker thread in case of a low-level error when
descriptors cannot be created (e.g. when there are too many open file
descriptors).

lib/isc/netmgr/tcp.c

index 80ce1193c2b1f9a676aea52b961226c04a041a48..60cf9222c5f85511e7fe44a4a3143f93f54b3253 100644 (file)
@@ -317,9 +317,13 @@ isc_nm_tcpconnect(isc_nm_t *mgr, isc_nmiface_t *local, isc_nmiface_t *peer,
        if (result != ISC_R_SUCCESS) {
                if (isc__nm_in_netthread()) {
                        sock->tid = isc_nm_tid();
+                       isc__nmsocket_clearcb(sock);
+                       isc__nm_connectcb(sock, req, result, false);
+               } else {
+                       isc__nmsocket_clearcb(sock);
+                       sock->tid = isc_random_uniform(mgr->nworkers);
+                       isc__nm_connectcb(sock, req, result, true);
                }
-               isc__nmsocket_clearcb(sock);
-               isc__nm_connectcb(sock, req, result, false);
                atomic_store(&sock->closed, true);
                isc__nmsocket_detach(&sock);
                return;