#1263·memcached

rcontext memory leak fixup

Author: urgordeadbeefCreated Jan 30, 2026Updated Mar 4, 2026

With proxy replication requests to several backends no any rcontexts with failed backends (depth limit, timeout, etc) will be freed. Memory grows up for such rcontexts infinitely.

Config for reproducing bug:

pools {
    set_test = {
        { backends = { "192.168.1.1:11211" } },
        { backends = { "192.168.1.2:11211" } },
        { backends = { "192.168.1.3:11211" } },
        { backends = { "192.168.1.4:11211" } },
    },
}
routes {
     default = route_allfastest {
        children = "set_test", miss = true,
     }
}

Patch for fixup this issue:

--- proxy_network.c.orig	2026-01-30 16:47:25.801337000 +0300
+++ proxy_network.c	2026-01-30 16:52:34.545392000 +0300
@@ -312,6 +312,7 @@
         mcp_resp_set_elapsed(io->client_resp);
         io->client_resp->status = MCMC_ERR;
         io->client_resp->resp.code = MCMC_CODE_SERVER_ERROR;
+	     io->rctx->pending_reqs--;
         be->depth--;
         assert(be->depth > -1);
         return_io_pending((io_pending_t *)io);
@@ -878,6 +879,7 @@
         mcp_resp_set_elapsed(io->client_resp);
         io->client_resp->status = MCMC_ERR;
         io->client_resp->resp.code = MCMC_CODE_SERVER_ERROR;
+	     io->rctx->pending_reqs--;
         be->depth--;
         assert(be->depth > -1);
         return_io_pending((io_pending_t *)io);