mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 00:04:15 -04:00
fix(cache): isolate metadata in prefetch goroutine (#7631)
Wrap doPrefetch with a fresh metadata context to prevent concurrent writes to the request-scoped metadata map during background prefetch. Add a new integration test configuring a plugin chain, triggering the issue seen here. Hammers concurrent queries while log reads metadata fields repeatedly. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
2
plugin/cache/handler.go
vendored
2
plugin/cache/handler.go
vendored
@@ -92,6 +92,8 @@ func wildcardFunc(ctx context.Context) func() string {
|
||||
}
|
||||
|
||||
func (c *Cache) doPrefetch(ctx context.Context, state request.Request, cw *ResponseWriter, i *item, now time.Time) {
|
||||
// Use a fresh metadata map to avoid concurrent writes to the original request's metadata.
|
||||
ctx = metadata.ContextWithMetadata(ctx)
|
||||
cachePrefetches.WithLabelValues(cw.server, c.zonesMetricLabel, c.viewMetricLabel).Inc()
|
||||
c.doRefresh(ctx, state, cw)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user