From: Vladimír Čunát Date: Fri, 21 May 2021 15:29:25 +0000 (+0200) Subject: lib/selection: be more careful with RO transactions X-Git-Tag: v5.4.0~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a23bb067a33d371d04a0ef6f55dd49adabb4023c;p=thirdparty%2Fknot-resolver.git lib/selection: be more careful with RO transactions They probably couldn't hang open for long, as each client request should cause some cache-searching and thus close it, and even with queries stopping I haven't managed to find a case where it would be left open but... it's nicer to clean up and it should be very cheap. --- diff --git a/lib/selection.h b/lib/selection.h index 02ef5b5a1..39261557d 100644 --- a/lib/selection.h +++ b/lib/selection.h @@ -254,6 +254,9 @@ uint8_t *ip_to_bytes(const union inaddr *src, size_t len); /** * @internal Fetch per-address information from various sources. + * + * Note that this opens a RO cache transaction; the callee is responsible + * for its closing not too long afterwards (e.g. calling kr_cache_commit). */ void update_address_state(struct address_state *state, union inaddr *address, size_t address_len, struct kr_query *qry); diff --git a/lib/selection_forward.c b/lib/selection_forward.c index ea2ec6ecf..cde634d56 100644 --- a/lib/selection_forward.c +++ b/lib/selection_forward.c @@ -53,7 +53,7 @@ void forward_choose_transport(struct kr_query *qry, default: kr_assert(false); *transport = NULL; - return; + goto cleanup; } struct address_state *addr_state = &local_state->addr_states[i]; @@ -94,6 +94,8 @@ void forward_choose_transport(struct kr_query *qry, qry->flags.TCP = (*transport)->protocol == KR_TRANSPORT_TCP || (*transport)->protocol == KR_TRANSPORT_TLS; } +cleanup: + kr_cache_commit(&qry->request->ctx->cache); } void forward_error(struct kr_query *qry, const struct kr_transport *transport, diff --git a/lib/selection_iter.c b/lib/selection_iter.c index b5b241c15..87206cc01 100644 --- a/lib/selection_iter.c +++ b/lib/selection_iter.c @@ -127,6 +127,7 @@ static void unpack_state_from_zonecut(struct iter_local_state *local_state, } } trie_it_free(it); + kr_cache_commit(&qry->request->ctx->cache); } static int get_valid_addresses(struct iter_local_state *local_state,