Skip to content

Commit 3f3e7f1

Browse files
committed
plugin_cache: restore proper error handling in cache initialization
The race condition fix in d943aba inadvertently changed error handling behavior by silently ignoring cache initialization failures. This could lead to degraded performance when the cache fails to initialize. Restore proper error propagation while maintaining thread safety using sync.Once and a captured error variable.
1 parent 94323d5 commit 3f3e7f1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

dnscrypt-proxy/plugin_cache.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"crypto/sha512"
55
"encoding/binary"
6+
"fmt"
67
"sync"
78
"time"
89

@@ -144,12 +145,18 @@ func (plugin *PluginCacheResponse) Eval(pluginsState *PluginsState, msg *dns.Msg
144145
expiration: time.Now().Add(ttl),
145146
msg: *msg,
146147
}
148+
var cacheInitError error
147149
cachedResponses.cacheOnce.Do(func() {
148150
cache, err := sievecache.NewSharded[[32]byte, CachedResponse](pluginsState.cacheSize)
149-
if err == nil {
151+
if err != nil {
152+
cacheInitError = err
153+
} else {
150154
cachedResponses.cache = cache
151155
}
152156
})
157+
if cacheInitError != nil {
158+
return fmt.Errorf("failed to initialize the cache: %w", cacheInitError)
159+
}
153160
if cachedResponses.cache != nil {
154161
cachedResponses.cache.Insert(cacheKey, cachedResponse)
155162
}

0 commit comments

Comments
 (0)