From d27f6f2d68f15f5ed698a6e19cb852dded5f88af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Sat, 8 Apr 2023 13:54:52 +0200 Subject: [PATCH] Accept overquota TCP connection on local thread if possible If the quota callback is called on a thread matching the socket, call the TCP accept function directly instead of using isc_async_run() which allocates-deallocates memory. --- lib/isc/netmgr/tcp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index b5c0facdc2..670db30579 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -865,8 +865,15 @@ quota_accept_cb(isc_quota_t *quota, void *arg) { * This needs to be asynchronous, because the quota might have been * released by a different child socket. */ - isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL }); - isc_async_run(sock->worker->loop, tcpaccept_cb, sock); + if (sock->tid == isc_tid()) { + isc_result_t result = accept_connection(sock); + isc__nm_accept_connection_log(sock, result, + can_log_tcp_quota()); + sock->pquota = NULL; + } else { + isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL }); + isc_async_run(sock->worker->loop, tcpaccept_cb, sock); + } } static isc_result_t