fix: restore tracing endpoint validation; honor per-side client timeouts; cache eviction target; redis close

- tracing: validateEndpoint used fmt.Sscanf("%s:%d") which treats %s as
  greedy, so every valid host:port endpoint failed and traced==nil disabled
  tracing entirely. Validate with net.SplitHostPort (pure helper, port range
  0-65535); test TestValidateEndpoint.
- proxy: createFasthttpClient used clientTimeout for every timeout slot,
  ignoring the parsed CLIENT_READ_TIMEOUT/CLIENT_WRITE_TIMEOUT (silent
  config loss, documented separately in README). Honour per-side read/write
  timeouts, falling back to client timeout when unset.
- cache/memory: evictToFreeMemory capped candidates at maxCacheSize/5 and
  stopped at the subset end, so a large write could leave the cache over
  its memory limit. Collect all entries and sort.Slice (correct + O(n log n)
  vs O(cap^2)), evict until the target is met or the cache is drained.
- cache/redis: the Redis cache client was never closed at shutdown (unlike
  the metrics aggregator). Add RedisConfig.Close, CacheWrapper.Close, a
  cache.Shutdown and register it with the ShutdownManager.
This commit is contained in:
2026-08-13 07:16:52 +01:00
parent fc28c65681
commit 14be2398e8
10 changed files with 167 additions and 37 deletions
+22
View File
@@ -72,6 +72,28 @@ func (suite *Tests) TestFasthttpClientConfiguration() {
// with the configured timeouts by testing requests
assert.NotNil(suite.T(), client, "Client should be created")
// The read/write timeouts must honour the per-side config
// (CLIENT_READ_TIMEOUT / CLIENT_WRITE_TIMEOUT), falling back to the
// client timeout.
want := time.Duration(tc.readTimeout) * time.Second
if tc.readTimeout <= 0 {
want = time.Duration(tc.clientTimeout) * time.Second
if want <= 0 {
want = 30 * time.Second
}
}
assert.Equal(suite.T(), want, client.ReadTimeout,
"client read timeout should honour CLIENT_READ_TIMEOUT")
want = time.Duration(tc.writeTimeout) * time.Second
if tc.writeTimeout <= 0 {
want = time.Duration(tc.clientTimeout) * time.Second
if want <= 0 {
want = 30 * time.Second
}
}
assert.Equal(suite.T(), want, client.WriteTimeout,
"client write timeout should honour CLIENT_WRITE_TIMEOUT")
// For non-zero configuration values, we can at least verify they were applied
// by checking the client isn't nil
assert.NotNil(suite.T(), client.TLSConfig, "TLS config should be created")