Skip to content

Commit 14372d6

Browse files
committed
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.
1 parent fa47d40 commit 14372d6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

internal/target/remote/remote.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (rt *Target) Init(cfg *config.Map) error {
146146
MaxKeys: 5000,
147147
MaxConnsPerKey: 5, // basically, max. amount of idle connections in cache
148148
MaxConnLifetimeSec: 150, // 2.5 mins, half of recommended idle time from RFC 5321
149-
StaleKeyLifetimeSec: 60 * 5, // should be bigger than MaxConnLifetimeSec
149+
StaleKeyLifetimeSec: 60 * 4, // make sure that cleanup runs before recommended idle time from RFC 5321
150150
}
151151
cfg.Int("conn_max_idle_count", false, false, 5, &poolCfg.MaxConnsPerKey)
152152
cfg.Int64("conn_max_idle_time", false, false, 150, &poolCfg.MaxConnLifetimeSec)

internal/target/remote/remote_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func testTarget(t *testing.T, zones map[string]mockdns.Zone, extResolver *dns.Ex
6464
MaxKeys: 5000,
6565
MaxConnsPerKey: 5, // basically, max. amount of idle connections in cache
6666
MaxConnLifetimeSec: 150, // 2.5 mins, half of recommended idle time from RFC 5321
67-
StaleKeyLifetimeSec: 60 * 5, // should be bigger than MaxConnLifetimeSec
67+
StaleKeyLifetimeSec: 60 * 4, // make sure that cleanup runs before recommended idle time from RFC 5321
6868
}),
6969
}
7070

0 commit comments

Comments
 (0)