]> git.ipfire.org Git - thirdparty/bind9.git/commit
Fix the streaming read callback shutdown logic
authorOndřej Surý <ondrej@isc.org>
Thu, 13 Apr 2023 15:27:50 +0000 (17:27 +0200)
committerOndřej Surý <ondrej@isc.org>
Thu, 20 Apr 2023 10:58:32 +0000 (12:58 +0200)
commit3b108145694bbb1f6459f5742569b2f0ceea9209
tree8855fd93497ead1dbad6927f68e3c4b04545bf49
parent4fcbb078c11d8f87f324da2a6d46c7449d6378f7
Fix the streaming read callback shutdown logic

When shutting down TCP sockets, the read callback calling logic was
flawed, it would call either one less callback or one extra.  Fix the
logic in the way:

1. When isc_nm_read() has been called but isc_nm_read_stop() hasn't on
   the handle, the read callback will be called with ISC_R_CANCELED to
   cancel active reading from the socket/handle.

2. When isc_nm_read() has been called and isc_nm_read_stop() has been
   called on the on the handle, the read callback will be called with
   ISC_R_SHUTTINGDOWN to signal that the dormant (not-reading) socket
   is being shut down.

3. The .reading and .recv_read flags are little bit tricky.  The
   .reading flag indicates if the outer layer is reading the data (that
   would be uv_tcp_t for TCP and isc_nmsocket_t (TCP) for TLSStream),
   the .recv_read flag indicates whether somebody is interested in the
   data read from the socket.

   Usually, you would expect that the .reading should be false when
   .recv_read is false, but it gets even more tricky with TLSStream as
   the TLS protocol might need to read from the socket even when sending
   data.

   Fix the usage of the .recv_read and .reading flags in the TLSStream
   to their true meaning - which mostly consist of using .recv_read
   everywhere and then wrapping isc_nm_read() and isc_nm_read_stop()
   with the .reading flag.

4. The TLS failed read helper has been modified to resemble the TCP code
   as much as possible, clearing and re-setting the .recv_read flag in
   the TCP timeout code has been fixed and .recv_read is now cleared
   when isc_nm_read_stop() has been called on the streaming socket.

5. The use of Network Manager in the named_controlconf, isccc_ccmsg, and
   isc_httpd units have been greatly simplified due to the improved design.

6. More unit tests for TCP and TLS testing the shutdown conditions have
   been added.

Co-authored-by: Ondřej Surý <ondrej@isc.org>
Co-authored-by: Artem Boldariev <artem@isc.org>
26 files changed:
bin/named/controlconf.c
bin/rndc/rndc.c
doc/design/netmgr.md
lib/isc/httpd.c
lib/isc/include/isc/netmgr.h
lib/isc/netmgr/http.c
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/streamdns.c
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tlsstream.c
lib/isc/netmgr/udp.c
lib/isccc/ccmsg.c
lib/isccc/include/isccc/ccmsg.h
tests/dns/dispatch_test.c
tests/isc/Makefile.am
tests/isc/netmgr_common.c
tests/isc/netmgr_common.h
tests/isc/stream_shutdown.c [new file with mode: 0644]
tests/isc/tcp_test.c
tests/isc/tcpdns_test.c
tests/isc/tls_test.c
tests/isc/tlsdns_test.c
tests/isc/udp_test.c
tests/libtest/isc.c
tests/ns/netmgr_wrap.c