bind9/lib/isc
Ondřej Surý bfa4b9c141 Run .closehandle_cb asynchrounosly in nmhandle_detach_cb()
When sock->closehandle_cb is set, we need to run nmhandle_detach_cb()
asynchronously to ensure correct order of multiple packets processing in
the isc__nm_process_sock_buffer().  When not run asynchronously, it
would cause:

  a) out-of-order processing of the return codes from processbuffer();

  b) stack growth because the next TCP DNS message read callback will
     be called from within the current TCP DNS message read callback.

The sock->closehandle_cb is set to isc__nm_resume_processing() for TCP
sockets which calls isc__nm_process_sock_buffer().  If the read callback
(called from isc__nm_process_sock_buffer()->processbuffer()) doesn't
attach to the nmhandle (f.e. because it wants to drop the processing or
we send the response directly via uv_try_write()), the
isc__nm_resume_processing() (via .closehandle_cb) would call
isc__nm_process_sock_buffer() recursively.

The below shortened code path shows how the stack can grow:

 1: ns__client_request(handle, ...);
 2: isc_nm_tcpdns_sequential(handle);
 3: ns_query_start(client, handle);
 4:   query_lookup(qctx);
 5:     query_send(qctcx->client);
 6:       isc__nmhandle_detach(&client->reqhandle);
 7:         nmhandle_detach_cb(&handle);
 8:           sock->closehandle_cb(sock); // isc__nm_resume_processing
 9:             isc__nm_process_sock_buffer(sock);
10:               processbuffer(sock); // isc__nm_tcpdns_processbuffer
11:                 isc_nmhandle_attach(req->handle, &handle);
12:                 isc__nm_readcb(sock, req, ISC_R_SUCCESS);
13:                   isc__nm_async_readcb(NULL, ...);
14:                     uvreq->cb.recv(...); // ns__client_request

Instead, if 'sock->closehandle_cb' is set, we need to run detach the
handle asynchroniously in 'isc__nmhandle_detach', so that on line 8 in
the code flow above does not start this recursion. This ensures the
correct order when processing multiple packets in the function
'isc__nm_process_sock_buffer()' and prevents the stack growth.

When not run asynchronously, the out-of-order processing leaves the
first TCP socket open until all requests on the stream have been
processed.

If the pipelining is disabled on the TCP via `keep-response-order`
configuration option, named would keep the first socket in lingering
CLOSE_WAIT state when the client sends an incomplete packet and then
closes the connection from the client side.
2022-03-16 22:11:49 +01:00
..
include Implement isc_interval_t on top of isc_time_t 2022-03-14 13:00:05 -07:00
netmgr Run .closehandle_cb asynchrounosly in nmhandle_detach_cb() 2022-03-16 22:11:49 +01:00
tests Refactor isc_timer_reset() use with semantic patch 2022-03-14 13:00:05 -07:00
.gitignore [master] update gitignore files; use rev-parse to get srcid 2014-06-17 13:49:30 -07:00
aes.c Remove EVP_CIPHER_CTX_new() and EVP_CIPHER_CTX_free() shims 2022-03-02 10:48:09 +00:00
app.c Remove usage of deprecated ATOMIC_VAR_INIT() macro 2022-03-08 23:55:10 +01:00
assertions.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
astack.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
backtrace.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
base32.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
base64.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
bind9.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
buffer.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
commandline.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
condition.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
counter.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
crc64.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
dir.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
entropy.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
entropy_private.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
errno.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
errno2result.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
errno2result.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
error.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
event.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
file.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess_common.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
fsaccess_common_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
glob.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
hash.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
heap.c Make isc_heap_create() and isc_heap_insert() return void 2022-03-08 11:19:34 +01:00
hex.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
hmac.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
ht.c Make isc_ht_init() and isc_ht_iter_create() return void 2022-03-08 14:51:55 +01:00
httpd.c Cleanup the nmhandle attach/detach in httpd.c 2022-03-11 09:57:10 +01:00
interfaceiter.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
iterated_hash.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
jemalloc_shim.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
lex.c Grow the lex token buffer in one more place 2022-03-01 16:05:39 -08:00
lib.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
log.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
Makefile.am Replace netievent lock-free queue with simple locked queue 2022-03-04 13:49:51 +01:00
managers.c Replace netievent lock-free queue with simple locked queue 2022-03-04 13:49:51 +01:00
md.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mem.c Remove usage of deprecated ATOMIC_VAR_INIT() macro 2022-03-08 23:55:10 +01:00
mem_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
meminfo.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mutex.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
mutexblock.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
net.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
netaddr.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
netmgr_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
netscope.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
nonce.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
openssl_shim.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
openssl_shim.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
os.c Use detected cache line size 2022-01-27 13:02:23 +01:00
os_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
parseint.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
pool.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
portset.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
quota.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
radix.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
random.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
ratelimiter.c Refactor isc_timer_reset() use with semantic patch 2022-03-14 13:00:05 -07:00
regex.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
region.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
resource.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
result.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
rwlock.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
safe.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
serial.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
siphash.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
sockaddr.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
stats.c Assert if statistics counter underflows in the developer mode 2022-02-10 17:18:09 +01:00
stdio.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
stdtime.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
string.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
symtab.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
syslog.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
task.c Replace netievent lock-free queue with simple locked queue 2022-03-04 13:49:51 +01:00
task_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
taskpool.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
thread.c Remove unused functions from isc_thread API 2022-02-09 17:22:06 +01:00
time.c Implement isc_interval_t on top of isc_time_t 2022-03-14 13:00:05 -07:00
timer.c Refactor isc_timer_reset() use with semantic patch 2022-03-14 13:00:05 -07:00
timer_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
tls.c Remove usage of deprecated ATOMIC_VAR_INIT() macro 2022-03-08 23:55:10 +01:00
tls_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
tm.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
trampoline.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
trampoline_p.h Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
url.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00
utf8.c Update the copyright information in all files in the repository 2022-01-11 09:05:02 +01:00