From 5e9d508e91b2029c108b7865ff053281005379e7 Mon Sep 17 00:00:00 2001 From: TJ Saunders Date: Sat, 17 Aug 2024 10:30:18 -0700 Subject: [PATCH] Attempt to more gracefully handle the case where the `session.notes` table is unexpectedly full. --- mod_proxy.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/mod_proxy.c b/mod_proxy.c index e4f0f80..fe9b1c2 100644 --- a/mod_proxy.c +++ b/mod_proxy.c @@ -5569,8 +5569,38 @@ static int proxy_sess_init(void) { * needed. */ proxy_sess = (struct proxy_session *) proxy_session_alloc(proxy_pool); - if (pr_table_add(session.notes, "mod_proxy.proxy-session", proxy_sess, - sizeof(struct proxy_session)) < 0) { + res = pr_table_add(session.notes, "mod_proxy.proxy-session", proxy_sess, + sizeof(struct proxy_session)); + + if (res < 0 && + errno == ENOSPC) { + int nents, nmaxents; + + nents = pr_table_count(session.notes); + nmaxents = nents * 2; + + /* Attempt to handle the unusual case where the table is full, since + * we really need this note. + */ + pr_trace_msg(trace_channel, 1, + "session notes table is full (%u), increasing entry limit to %u", + nents, nmaxents); + + if (pr_table_ctl(session.notes, PR_TABLE_CTL_SET_MAX_ENTS, + &nmaxents) == 0) { + res = pr_table_add(session.notes, "mod_proxy.proxy-session", proxy_sess, + sizeof(struct proxy_session)); + + } else { + (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, + "error increasing session notes max entries: %s", strerror(errno)); + + res = -1; + errno = ENOSPC; + } + } + + if (res < 0) { (void) pr_log_writefile(proxy_logfd, MOD_PROXY_VERSION, "error stashing proxy session note: %s", strerror(errno));