Merge branch '999-tcp-client-crash-v9_11-locks-v9_14-master' into 'master'

Replace atomic operations in bin/named/client.c with isc_refcount reference counting

Closes #999

See merge request isc-projects/bind9!1881
This commit is contained in:
Ondřej Surý 2019-04-26 16:25:49 -04:00
commit f3a242d71d
3 changed files with 14 additions and 10 deletions

View file

@ -421,11 +421,11 @@ tcpconn_detach(ns_client_t *client) {
static void
mark_tcp_active(ns_client_t *client, bool active) {
if (active && !client->tcpactive) {
atomic_fetch_add(&client->interface->ntcpactive, 1);
isc_refcount_increment0(&client->interface->ntcpactive);
client->tcpactive = active;
} else if (!active && client->tcpactive) {
uint32_t old =
atomic_fetch_sub(&client->interface->ntcpactive, 1);
isc_refcount_decrement(&client->interface->ntcpactive);
INSIST(old > 0);
client->tcpactive = active;
}
@ -573,7 +573,7 @@ exit_check(ns_client_t *client) {
if (client->mortal && TCP_CLIENT(client) &&
client->newstate != NS_CLIENTSTATE_FREED &&
(client->sctx->options & NS_SERVER_CLIENTTEST) == 0 &&
atomic_load(&client->interface->ntcpaccepting) == 0)
isc_refcount_current(&client->interface->ntcpaccepting) == 0)
{
/* Nobody else is accepting */
client->mortal = false;
@ -3325,7 +3325,7 @@ client_newconn(isc_task_t *task, isc_event_t *event) {
INSIST(client->naccepts == 1);
client->naccepts--;
old = atomic_fetch_sub(&client->interface->ntcpaccepting, 1);
old = isc_refcount_decrement(&client->interface->ntcpaccepting);
INSIST(old > 0);
/*
@ -3455,7 +3455,7 @@ client_accept(ns_client_t *client) {
* quota is tcp-clients plus the number of listening
* interfaces plus 1.)
*/
exit = (atomic_load(&client->interface->ntcpactive) >
exit = (isc_refcount_current(&client->interface->ntcpactive) >
(client->tcpactive ? 1U : 0U));
if (exit) {
client->newstate = NS_CLIENTSTATE_INACTIVE;
@ -3514,7 +3514,7 @@ client_accept(ns_client_t *client) {
* listening for connections itself to prevent the interface
* going dead.
*/
atomic_fetch_add(&client->interface->ntcpaccepting, 1);
isc_refcount_increment0(&client->interface->ntcpaccepting);
}
static void

View file

@ -45,6 +45,7 @@
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/socket.h>
#include <isc/refcount.h>
#include <dns/geoip.h>
#include <dns/result.h>
@ -76,11 +77,11 @@ struct ns_interface {
/*%< UDP dispatchers. */
isc_socket_t * tcpsocket; /*%< TCP socket. */
isc_dscp_t dscp; /*%< "listen-on" DSCP value */
atomic_uint_fast32_t ntcpaccepting; /*%< Number of clients
isc_refcount_t ntcpaccepting; /*%< Number of clients
ready to accept new
TCP connections on this
interface */
atomic_uint_fast32_t ntcpactive; /*%< Number of clients
isc_refcount_t ntcpactive; /*%< Number of clients
servicing TCP queries
(whether accepting or
connected) */

View file

@ -423,8 +423,8 @@ ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
* connections will be handled in parallel even though there is
* only one client initially.
*/
atomic_init(&ifp->ntcpaccepting, 0);
atomic_init(&ifp->ntcpactive, 0);
isc_refcount_init(&ifp->ntcpaccepting, 0);
isc_refcount_init(&ifp->ntcpactive, 0);
ifp->nudpdispatch = 0;
@ -657,6 +657,9 @@ ns_interface_destroy(ns_interface_t *ifp) {
ns_interfacemgr_detach(&ifp->mgr);
isc_refcount_destroy(&ifp->ntcpactive);
isc_refcount_destroy(&ifp->ntcpaccepting);
ifp->magic = 0;
isc_mem_put(mctx, ifp, sizeof(*ifp));
}