@@ -10,6 +10,8 @@ import (
1010 "github.com/miekg/dns"
1111)
1212
13+ const StaleResponseTtl = 30 * time .Second
14+
1315type CachedResponse struct {
1416 expiration time.Time
1517 msg dns.Msg
@@ -68,30 +70,35 @@ func (plugin *PluginCache) Reload() error {
6870
6971func (plugin * PluginCache ) Eval (pluginsState * PluginsState , msg * dns.Msg ) error {
7072 cacheKey := computeCacheKey (pluginsState , msg )
73+
7174 cachedResponses .RLock ()
72- defer cachedResponses .RUnlock ()
7375 if cachedResponses .cache == nil {
76+ cachedResponses .RUnlock ()
7477 return nil
7578 }
7679 cachedAny , ok := cachedResponses .cache .Get (cacheKey )
7780 if ! ok {
81+ cachedResponses .RUnlock ()
7882 return nil
7983 }
8084 cached := cachedAny .(CachedResponse )
81-
85+ expiration := cached . expiration
8286 synth := cached .msg .Copy ()
87+ cachedResponses .RUnlock ()
88+
8389 synth .Id = msg .Id
8490 synth .Response = true
8591 synth .Compress = true
8692 synth .Question = msg .Question
8793
88- if time .Now ().After (cached .expiration ) {
89- updateTTL (synth , time .Now ().Add (30 * time .Second ))
94+ if time .Now ().After (expiration ) {
95+ expiration2 := time .Now ().Add (StaleResponseTtl )
96+ updateTTL (synth , expiration2 )
9097 pluginsState .sessionData ["stale" ] = synth
9198 return nil
9299 }
93100
94- updateTTL (synth , cached . expiration )
101+ updateTTL (synth , expiration )
95102
96103 pluginsState .synthResponse = synth
97104 pluginsState .action = PluginsActionSynth
0 commit comments