From 8510c5cd59e88d74d697376ec596dcbc54f34d66 Mon Sep 17 00:00:00 2001 From: Artem Boldariev Date: Fri, 23 Apr 2021 17:50:04 +0300 Subject: [PATCH] Always call TCP connect callback from within a worker context 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 80ce1193c2..60cf9222c5 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -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;