From a23bb067a33d371d04a0ef6f55dd49adabb4023c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Fri, 21 May 2021 17:29:25 +0200 Subject: [PATCH] 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. --- lib/selection.h | 3 +++ lib/selection_forward.c | 4 +++- lib/selection_iter.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) 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, -- 2.47.2