@@ -49,6 +49,13 @@ type SRVUpstreams struct {
49
49
// Results are cached between lookups. Default: 1m
50
50
Refresh caddy.Duration `json:"refresh,omitempty"`
51
51
52
+ // If > 0 and there is an error with the lookup,
53
+ // continue to use the cached results for up to
54
+ // this long before trying again, (even though they
55
+ // are stale) instead of returning an error to the
56
+ // client. Default: 0s.
57
+ GracePeriod caddy.Duration `json:"grace_period,omitempty"`
58
+
52
59
// Configures the DNS resolver used to resolve the
53
60
// SRV address to SRV records.
54
61
Resolver * UpstreamResolver `json:"resolver,omitempty"`
@@ -140,6 +147,12 @@ func (su SRVUpstreams) GetUpstreams(r *http.Request) ([]*Upstream, error) {
140
147
// out and an error will be returned alongside the remaining results, if any." Thus, we
141
148
// only return an error if no records were also returned.
142
149
if len (records ) == 0 {
150
+ if su .GracePeriod > 0 {
151
+ su .logger .Error ("SRV lookup failed; using previously cached" , zap .Error (err ))
152
+ cached .freshness = time .Now ().Add (time .Duration (su .GracePeriod ) - time .Duration (su .Refresh ))
153
+ srvs [suAddr ] = cached
154
+ return allNew (cached .upstreams ), nil
155
+ }
143
156
return nil , err
144
157
}
145
158
su .logger .Warn ("SRV records filtered" , zap .Error (err ))
0 commit comments