]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move the dns_db_setloop into cache_create_db()
authorOndřej Surý <ondrej@isc.org>
Wed, 6 Mar 2024 17:14:32 +0000 (18:14 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 6 Mar 2024 17:33:33 +0000 (18:33 +0100)
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.

lib/dns/cache.c

index 4abd771ec11cddb08b3d951d5e5e4f75c66196d7..d425316cc463ae4c892706a6f55cd4220f67494d 100644 (file)
@@ -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));