Skip to content

Commit 570d782

Browse files
committed
prevent concurrent map access in kube-openapi dependencies
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent e6c6375 commit 570d782

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/server/openapiv3/servicecache.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ func (c *ServiceCache) RegisterStaticAPIs(cont *restful.Container) error {
104104
for gvPath, ws := range byGVPath {
105105
c.staticSpecs[gvPath] = cached.Once(cached.Func[*spec3.OpenAPI](
106106
func() (value *spec3.OpenAPI, etag string, err error) {
107-
spec, err := builder3.BuildOpenAPISpecFromRoutes(restfuladapter.AdaptWebServices(ws), c.config)
107+
// Copy the config and clear Definitions so that newOpenAPI() calls
108+
// GetDefinitions, creating a fresh definitions map per invocation.
109+
// Without this, the caching layer's listMerger evaluates multiple
110+
// closures in parallel and they all share the same Definitions map.
111+
// buildDefinitionRecursively mutates Extension maps reachable
112+
// through that shared map, causing concurrent map writes.
113+
cfg := *c.config
114+
cfg.Definitions = nil
115+
spec, err := builder3.BuildOpenAPISpecFromRoutes(restfuladapter.AdaptWebServices(ws), &cfg)
108116
if err != nil {
109117
return nil, "", fmt.Errorf("failed to build OpenAPI v3 spec for %s: %w", gvPath, err)
110118
}

0 commit comments

Comments
 (0)