From 641e87a1a0ee716f46b4d0f529e73b58f19aee4e Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Wed, 23 Jan 2013 14:28:23 -0800 Subject: [PATCH] [master] avoid active-counter underflow 3472. [bug] The active-connections counter in the socket statistics could underflow. [RT #31747] (cherry picked from commit 4dfe072abe4e76f5078a38ea0b97800333290877) --- CHANGES | 3 +++ lib/isc/unix/socket.c | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index 0ec2654fb5..0926ca4d03 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3472. [bug] The active-connections counter in the socket + statistics could underflow. [RT #31747] + 3471. [bug] The number of UDP dispatches now defaults to the number of CPUs even if -n has been set to a higher value. [RT #30964] diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 2697fbefcb..fe626343fb 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -326,16 +326,17 @@ struct isc__socket { intev_t readable_ev; intev_t writable_ev; - isc_sockaddr_t peer_address; /* remote address */ + isc_sockaddr_t peer_address; /* remote address */ unsigned int pending_recv : 1, pending_send : 1, pending_accept : 1, - listener : 1, /* listener socket */ + listener : 1, /* listener socket */ connected : 1, - connecting : 1, /* connect pending */ - bound : 1, /* bound to local addr */ - dupped : 1; + connecting : 1, /* connect pending */ + bound : 1, /* bound to local addr */ + dupped : 1, + active : 1; /* currently active */ #ifdef ISC_NET_RECVOVERFLOW unsigned char overflow; /* used for MSG_TRUNC fake */ @@ -1995,7 +1996,10 @@ closesocket(isc__socketmgr_t *manager, isc__socket_t *sock, int fd) { select_poke(manager, fd, SELECT_POKE_CLOSE); inc_stats(manager->stats, sock->statsindex[STATID_CLOSE]); - dec_stats(manager->stats, sock->statsindex[STATID_ACTIVE]); + if (sock->active == 1) { + dec_stats(manager->stats, sock->statsindex[STATID_ACTIVE]); + sock->active = 0; + } /* * update manager->maxfd here (XXX: this should be implemented more @@ -2582,7 +2586,11 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, setup_done: inc_stats(manager->stats, sock->statsindex[STATID_OPEN]); - inc_stats(manager->stats, sock->statsindex[STATID_ACTIVE]); + if (sock->active == 0) { + inc_stats(manager->stats, sock->statsindex[STATID_ACTIVE]); + sock->active = 1; + } + return (ISC_R_SUCCESS); } @@ -2625,6 +2633,7 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, INSIST(0); } + sock->active = 0; sock->pf = pf; result = opensocket(manager, sock, (isc__socket_t *)dup_socket);