2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-02 07:35:26 +00:00

Remove read callback before detaching from inner socket in tcpdns

This commit is contained in:
Witold Kręcicki
2019-12-08 23:09:16 +01:00
parent 86a847314a
commit a34ced776e
2 changed files with 20 additions and 7 deletions

View File

@@ -765,10 +765,14 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
.base = (unsigned char *) buf->base, .base = (unsigned char *) buf->base,
.length = nread .length = nread
}; };
/*
INSIST(sock->rcb.recv != NULL); * This might happen if the inner socket is closing.
sock->rcb.recv(sock->tcphandle, &region, sock->rcbarg); * 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->read_timeout = (atomic_load(&sock->keepalive)
? sock->mgr->keepalive ? sock->mgr->keepalive
: sock->mgr->idle); : sock->mgr->idle);
@@ -786,8 +790,14 @@ read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
if (sock->quota) { if (sock->quota) {
isc_quota_detach(&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 * We don't need to clean up now; the socket will be closed and
* resources and quota reclaimed when handle is freed in * resources and quota reclaimed when handle is freed in
@@ -1067,7 +1077,9 @@ void
isc__nm_tcp_shutdown(isc_nmsocket_t *sock) { isc__nm_tcp_shutdown(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(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); sock->rcb.recv(sock->tcphandle, NULL, sock->rcbarg);
} }
} }

View File

@@ -494,6 +494,7 @@ static void
tcpdns_close_direct(isc_nmsocket_t *sock) { tcpdns_close_direct(isc_nmsocket_t *sock) {
REQUIRE(sock->tid == isc_nm_tid()); REQUIRE(sock->tid == isc_nm_tid());
if (sock->outer != NULL) { if (sock->outer != NULL) {
sock->outer->rcb.recv = NULL;
isc_nmsocket_detach(&sock->outer); isc_nmsocket_detach(&sock->outer);
} }
/* We don't need atomics here, it's all in single network thread */ /* We don't need atomics here, it's all in single network thread */