From 14372d6aeb6b3babdb2a291af97e68cadf500edc Mon Sep 17 00:00:00 2001 From: Carl-Friedrich Braun Date: Mon, 26 May 2025 11:52:43 +0200 Subject: [PATCH] fix: reduce StaleKeyLifetimeSec to 4 minutes RFC 5321 recommends idle time of 5 minutes. Maddy runs pool cleanup once per minute. When a connection is returned to the pool at time 'last cleanup + 10 seconds', it will be closed at 'last cleanup + StaleKeyLifetimeSec + 60 seconds' . With the original value of 5 minutes, the connection will be closed 50 seconds after the recommended timeout. By reducing the lifetime to 4 minutes, connections might be closed a little early, but never late. --- internal/target/remote/remote.go | 2 +- internal/target/remote/remote_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/target/remote/remote.go b/internal/target/remote/remote.go index d4c42ed6..3f848832 100644 --- a/internal/target/remote/remote.go +++ b/internal/target/remote/remote.go @@ -146,7 +146,7 @@ func (rt *Target) Init(cfg *config.Map) error { MaxKeys: 5000, MaxConnsPerKey: 5, // basically, max. amount of idle connections in cache MaxConnLifetimeSec: 150, // 2.5 mins, half of recommended idle time from RFC 5321 - StaleKeyLifetimeSec: 60 * 5, // should be bigger than MaxConnLifetimeSec + StaleKeyLifetimeSec: 60 * 4, // make sure that cleanup runs before recommended idle time from RFC 5321 } cfg.Int("conn_max_idle_count", false, false, 5, &poolCfg.MaxConnsPerKey) cfg.Int64("conn_max_idle_time", false, false, 150, &poolCfg.MaxConnLifetimeSec) diff --git a/internal/target/remote/remote_test.go b/internal/target/remote/remote_test.go index 4998e0c6..c21bb6eb 100644 --- a/internal/target/remote/remote_test.go +++ b/internal/target/remote/remote_test.go @@ -64,7 +64,7 @@ func testTarget(t *testing.T, zones map[string]mockdns.Zone, extResolver *dns.Ex MaxKeys: 5000, MaxConnsPerKey: 5, // basically, max. amount of idle connections in cache MaxConnLifetimeSec: 150, // 2.5 mins, half of recommended idle time from RFC 5321 - StaleKeyLifetimeSec: 60 * 5, // should be bigger than MaxConnLifetimeSec + StaleKeyLifetimeSec: 60 * 4, // make sure that cleanup runs before recommended idle time from RFC 5321 }), }