From f303f9df08bfc16ec737d1dcef0cb72ecc80a278 Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Thu, 19 Sep 2024 10:31:37 -0400 Subject: [PATCH 1/2] remove dns client's active requests from ziti_dns.requests when closing client (cherry picked from commit 492d3074d42d87036196e50ec5e02cb7a8bd9e15) --- lib/ziti-tunnel-cbs/ziti_dns.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ziti-tunnel-cbs/ziti_dns.c b/lib/ziti-tunnel-cbs/ziti_dns.c index 11d39218d..032deac3f 100644 --- a/lib/ziti-tunnel-cbs/ziti_dns.c +++ b/lib/ziti-tunnel-cbs/ziti_dns.c @@ -240,10 +240,19 @@ void* on_dns_client(const void *app_intercept_ctx, io_ctx_t *io) { return clt; } +static void remove_dns_req(void *p) { + struct dns_req *req = p; + if (req) { + model_map_remove_key(&ziti_dns.requests, &req->id, sizeof(req->id)); + } +} + int on_dns_close(void *dns_io_ctx) { ZITI_LOG(TRACE, "DNS client close"); ziti_dns_client_t *clt = dns_io_ctx; - model_map_clear(&clt->active_reqs, NULL); + // we may be here due to udp timeout, and reqs may have been sent to upstream. + // remove reqs from ziti_dns to prevent completion (with invalid io_ctx) if upstream should respond after udp timeout. + model_map_clear(&clt->active_reqs, remove_dns_req); ziti_tunneler_close(clt->io_ctx->tnlr_io); free(clt->io_ctx); free(dns_io_ctx); From 03a99df100f7e82c56c2a4bb5c4f730078117f8e Mon Sep 17 00:00:00 2001 From: Shawn Carey Date: Thu, 19 Sep 2024 10:53:04 -0400 Subject: [PATCH 2/2] free dns req (cherry picked from commit ac813ea350f0cd6e3b3323e6fca2443468d2108c) --- lib/ziti-tunnel-cbs/ziti_dns.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ziti-tunnel-cbs/ziti_dns.c b/lib/ziti-tunnel-cbs/ziti_dns.c index 032deac3f..e02bd9a24 100644 --- a/lib/ziti-tunnel-cbs/ziti_dns.c +++ b/lib/ziti-tunnel-cbs/ziti_dns.c @@ -244,6 +244,7 @@ static void remove_dns_req(void *p) { struct dns_req *req = p; if (req) { model_map_remove_key(&ziti_dns.requests, &req->id, sizeof(req->id)); + free_dns_req(req); } }