2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

Refactor the isc_quota code and fix the quota in TCP accept code

In e185412872, the TCP accept quota code
became broken in a subtle way - the quota would get initialized on the
first accept for the server socket and then deleted from the server
socket, so it would never get applied again.

Properly fixing this required a bigger refactoring of the isc_quota API
code to make it much simpler.  The new code decouples the ownership of
the quota and acquiring/releasing the quota limit.

After (during) the refactoring it became more clear that we need to use
the callback from the child side of the accepted connection, and not the
server side.
This commit is contained in:
Ondřej Surý
2023-04-11 07:54:58 +02:00
parent 1768522045
commit 1715cad685
13 changed files with 210 additions and 433 deletions

View File

@@ -487,10 +487,7 @@ nmsocket_cleanup(void *arg) {
nmhandle_free(sock, handle);
}
if (sock->quota != NULL) {
isc_quota_detach(&sock->quota);
}
INSIST(sock->server == NULL);
sock->pquota = NULL;
isc__nm_tls_cleanup_data(sock);
@@ -707,6 +704,7 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc__networker_t *worker,
.active_link = ISC_LINK_INITIALIZER,
.active = true,
.job = ISC_JOB_INITIALIZER,
.quotacb = ISC_JOB_INITIALIZER,
};
if (iface != NULL) {
@@ -1058,35 +1056,6 @@ isc__nm_failed_send_cb(isc_nmsocket_t *sock, isc__nm_uvreq_t *req,
}
}
void
isc__nm_failed_accept_cb(isc_nmsocket_t *sock, isc_result_t eresult) {
REQUIRE(sock->accepting);
REQUIRE(sock->server);
/*
* Detach the quota early to make room for other connections;
* otherwise it'd be detached later asynchronously, and clog
* the quota unnecessarily.
*/
if (sock->quota != NULL) {
isc_quota_detach(&sock->quota);
}
isc__nmsocket_detach(&sock->server);
sock->accepting = false;
switch (eresult) {
case ISC_R_NOTCONNECTED:
/* IGNORE: The client disconnected before we could accept */
break;
default:
isc__nmsocket_log(sock, ISC_LOG_ERROR,
"Accepting TCP connection failed: %s",
isc_result_totext(eresult));
}
}
void
isc__nm_failed_connect_cb(isc_nmsocket_t *sock, isc__nm_uvreq_t *req,
isc_result_t eresult, bool async) {