Skip to content

Commit

Permalink
Fix cacheAlmostFull calculation for unbounded caches (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
skirsten committed Dec 15, 2021
1 parent 924f315 commit 9b2c6ac
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ func (cfg *Config) getCertDuringHandshake(hello *tls.ClientHelloInfo, loadIfNece
// perfectly full while still being able to load needed certs from storage.
// See https://caddy.community/t/error-tls-alert-internal-error-592-again/13272
// and caddyserver/caddy#4320.
cacheAlmostFull := float64(cacheSize) >= (float64(cfg.certCache.options.Capacity) * .9)
cacheCapacity := float64(cfg.certCache.options.Capacity)
cacheAlmostFull := cacheCapacity > 0 && float64(cacheSize) >= cacheCapacity*.9
loadDynamically := cfg.OnDemand != nil || cacheAlmostFull

if loadDynamically && loadIfNecessary {
Expand Down Expand Up @@ -323,7 +324,7 @@ func (cfg *Config) getCertDuringHandshake(hello *tls.ClientHelloInfo, loadIfNece
zap.String("remote", hello.Conn.RemoteAddr().String()),
zap.String("identifier", name),
zap.Uint16s("cipher_suites", hello.CipherSuites),
zap.Float64("cert_cache_fill", float64(cacheSize)/float64(cfg.certCache.options.Capacity)), // may be approximate! because we are not within the lock
zap.Float64("cert_cache_fill", float64(cacheSize)/cacheCapacity), // may be approximate! because we are not within the lock
zap.Bool("load_if_necessary", loadIfNecessary),
zap.Bool("obtain_if_necessary", obtainIfNecessary),
zap.Bool("on_demand", cfg.OnDemand != nil))
Expand Down

0 comments on commit 9b2c6ac

Please sign in to comment.