From: Ondřej Surý Date: Wed, 6 Mar 2024 17:14:32 +0000 (+0100) Subject: Move the dns_db_setloop into cache_create_db() X-Git-Tag: v9.19.22~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d492d676ef16d1dc8e78985adf77772b82f2d8ad;p=thirdparty%2Fbind9.git Move the dns_db_setloop into cache_create_db() The dns_cache_flush() drops the old database and creates a new one, but it forgets to pass the loop that runs the node pruning and cleaning the rbtdb when flushing it next time. This causes the cleaning to skip cleaning the parent nodes (with .down == NULL) leading to increased memory usage over time until the database is unable to keep up and just stays overmem all the time. --- diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 4abd771ec11..d425316cc46 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -68,6 +68,7 @@ struct dns_cache { isc_mutex_t lock; isc_mem_t *mctx; /* Main cache memory */ isc_mem_t *hmctx; /* Heap memory */ + isc_loop_t *loop; char *name; isc_refcount_t references; @@ -101,6 +102,9 @@ cache_create_db(dns_cache_t *cache, dns_db_t **db) { dns_db_setservestalettl(*db, cache->serve_stale_ttl); dns_db_setservestalerefresh(*db, cache->serve_stale_refresh); } + + dns_db_setloop(cache->db, cache->loop); + return (result); } @@ -137,6 +141,7 @@ dns_cache_create(isc_loopmgr_t *loopmgr, dns_rdataclass_t rdclass, .hmctx = hmctx, .rdclass = rdclass, .name = isc_mem_strdup(mctx, cachename), + .loop = isc_loop_ref(isc_loop_main(loopmgr)), }; isc_mutex_init(&cache->lock); @@ -174,6 +179,7 @@ cleanup_stats: isc_stats_detach(&cache->stats); isc_mutex_destroy(&cache->lock); isc_mem_free(mctx, cache->name); + isc_loop_detach(&cache->loop); isc_mem_detach(&cache->hmctx); isc_mem_putanddetach(&cache->mctx, cache, sizeof(*cache)); return (result); @@ -192,6 +198,8 @@ cache_free(dns_cache_t *cache) { isc_mutex_destroy(&cache->lock); + isc_loop_detach(&cache->loop); + cache->magic = 0; isc_mem_detach(&cache->hmctx); isc_mem_putanddetach(&cache->mctx, cache, sizeof(*cache));