]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/selection: be more careful with RO transactions
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 21 May 2021 15:29:25 +0000 (17:29 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Fri, 18 Jun 2021 10:54:46 +0000 (12:54 +0200)
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
lib/selection_forward.c
lib/selection_iter.c

index 02ef5b5a1dc3d6d410140fbeb36dbf36b3f18577..39261557de4158a7cb8d8744d6422a63f4eb7cc4 100644 (file)
@@ -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);
index ea2ec6ecf13b3f5af5f7094a07c2e0311b4dc3be..cde634d569754f836867a92a5d9b378ebc63cf94 100644 (file)
@@ -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,
index b5b241c1585092d81d21a6ca088cdcdbc1af2ad2..87206cc014f5a7424f4cf2c02d88e01ba20d59d7 100644 (file)
@@ -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,