]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove read callback before detaching from inner socket in tcpdns
authorWitold Kręcicki <wpk@isc.org>
Sun, 8 Dec 2019 22:09:16 +0000 (23:09 +0100)
committerWitold Kręcicki <wpk@isc.org>
Mon, 9 Dec 2019 20:44:04 +0000 (21:44 +0100)
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tcpdns.c

index 7e3972d07aed7678cdd97b0cde4519749659a31d..852c3cd4d6c9189e3ce31b5ae8f89d2fdb6cb4c7 100644 (file)
@@ -765,10 +765,14 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
                        .base = (unsigned char *) buf->base,
                        .length = nread
                };
-
-               INSIST(sock->rcb.recv != NULL);
-               sock->rcb.recv(sock->tcphandle, &region, sock->rcbarg);
-
+               /*
+                * This might happen if the inner socket is closing.
+                * It means that it's detached, so the socket will
+                * be closed.
+                */
+               if (sock->rcb.recv != NULL) {
+                       sock->rcb.recv(sock->tcphandle, &region, sock->rcbarg);
+               }
                sock->read_timeout = (atomic_load(&sock->keepalive)
                                      ? sock->mgr->keepalive
                                      : sock->mgr->idle);
@@ -786,8 +790,14 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
        if (sock->quota) {
                isc_quota_detach(&sock->quota);
        }
-       sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
-
+       /*
+        * This might happen if the inner socket is closing.
+        * It means that it's detached, so the socket will
+        * be closed.
+        */
+       if (sock->rcb.recv != NULL) {
+               sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
+       }
        /*
         * We don't need to clean up now; the socket will be closed and
         * resources and quota reclaimed when handle is freed in
@@ -1067,7 +1077,9 @@ void
 isc__nm_tcp_shutdown(isc_nmsocket_t *sock) {
        REQUIRE(VALID_NMSOCK(sock));
 
-       if (sock->type == isc_nm_tcpsocket && sock->tcphandle != NULL) {
+       if (sock->type == isc_nm_tcpsocket &&
+           sock->tcphandle != NULL &&
+           sock->rcb.recv != NULL) {
                sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
        }
 }
index ad53aeface361011f4ac674e0a6f272b64270a0f..94fb021bc650f42b32a0298ea53c0b70592f2d23 100644 (file)
@@ -494,6 +494,7 @@ static void
 tcpdns_close_direct(isc_nmsocket_t *sock) {
        REQUIRE(sock->tid == isc_nm_tid());
        if (sock->outer != NULL) {
+               sock->outer->rcb.recv = NULL;
                isc_nmsocket_detach(&sock->outer);
        }
        /* We don't need atomics here, it's all in single network thread */