Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATA RACE in kyaml 0.18.1, openapi package - globalSchema.namespaceabilityByResourceType #5805

Open
chlunde opened this issue Nov 21, 2024 · 2 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@chlunde
Copy link
Contributor

chlunde commented Nov 21, 2024

What happened?

I ran krusty.(*Kustomizer).Run() in two goroutines with the Go race detector enabled, and a data race was reported. The two goroutines access globalSchema.namespaceabilityByResourceType:

The following lines is a shortened output whichs shows how to achieve this via two different public methods on the openapi package:

WARNING: DATA RACE

Write at 0x000006ddedb8 by goroutine 91:
  sigs.k8s.io/kustomize/kyaml/openapi.findNamespaceability()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:760 +0x64
  sigs.k8s.io/kustomize/kyaml/openapi.parse()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:749 +0x4cf
  sigs.k8s.io/kustomize/kyaml/openapi.parseBuiltinSchema()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:713 +0x19d
  sigs.k8s.io/kustomize/kyaml/openapi.initSchema()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:683 +0x2fb
  sigs.k8s.io/kustomize/kyaml/openapi.SchemaForResourceType()

Previous read at 0x000006ddedb8 by goroutine 83:
  sigs.k8s.io/kustomize/kyaml/openapi.IsNamespaceScoped()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:410 +0x87
  sigs.k8s.io/kustomize/kyaml/openapi.IsCertainlyClusterScoped()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:448 +0x1ec
full log
==================
WARNING: DATA RACE
Write at 0x000006ddedb8 by goroutine 91:
  sigs.k8s.io/kustomize/kyaml/openapi.findNamespaceability()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:760 +0x64
  sigs.k8s.io/kustomize/kyaml/openapi.parse()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:749 +0x4cf
  sigs.k8s.io/kustomize/kyaml/openapi.parseBuiltinSchema()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:713 +0x19d
  sigs.k8s.io/kustomize/kyaml/openapi.initSchema()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:683 +0x2fb
  sigs.k8s.io/kustomize/kyaml/openapi.SchemaForResourceType()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:198 +0xb99
  sigs.k8s.io/kustomize/kyaml/yaml/walk.Walker.GetSchema()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/yaml/walk/walk.go:125 +0xc21
  sigs.k8s.io/kustomize/kyaml/yaml/walk.Walker.Walk()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/yaml/walk/walk.go:57 +0x137
  sigs.k8s.io/kustomize/kyaml/yaml/merge2.Merge()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/yaml/merge2/merge2.go:20 +0x217
  sigs.k8s.io/kustomize/api/filters/patchstrategicmerge.Filter.Filter()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filters/patchstrategicmerge/patchstrategicmerge.go:22 +0xa5
  sigs.k8s.io/kustomize/api/resource.(*Resource).ApplyFilter()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resource/resource.go:516 +0x93
  sigs.k8s.io/kustomize/api/resource.(*Resource).ApplySmPatch()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resource/resource.go:497 +0x133
  sigs.k8s.io/kustomize/api/internal/builtins.(*PatchTransformerPlugin).transformStrategicMerge()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/builtins/PatchTransformer.go:116 +0x515
  sigs.k8s.io/kustomize/api/internal/builtins.(*PatchTransformerPlugin).Transform()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/builtins/PatchTransformer.go:87 +0x50
  sigs.k8s.io/kustomize/api/internal/target.(*multiTransformer).Transform()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/multitransformer.go:30 +0xd2
  sigs.k8s.io/kustomize/api/internal/accumulator.(*ResAccumulator).Transform()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/accumulator/resaccumulator.go:141 +0x284
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).runTransformers()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:343 +0x28f
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:237 +0x6ee
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:194 +0x229
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:135 +0x105
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:126 +0x4fc
  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/krusty/kustomizer.go:90 +0x4ef


Previous read at 0x000006ddedb8 by goroutine 83:
  sigs.k8s.io/kustomize/kyaml/openapi.IsNamespaceScoped()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:410 +0x87
  sigs.k8s.io/kustomize/kyaml/openapi.IsCertainlyClusterScoped()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/openapi/openapi.go:448 +0x1ec
  sigs.k8s.io/kustomize/kyaml/resid.NewGvk()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resid/gvk.go:27 +0xff
  sigs.k8s.io/kustomize/kyaml/resid.GvkFromNode()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resid/gvk.go:33 +0x12b
  sigs.k8s.io/kustomize/api/resource.(*Resource).GetGvk()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resource/resource.go:57 +0x68
  sigs.k8s.io/kustomize/api/resource.(*Resource).CurId()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resource/resource.go:462 +0xa1
  sigs.k8s.io/kustomize/api/resmap.GetCurrentId()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resmap/reswrangler.go:171 +0x64
  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).filteredById()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resmap/reswrangler.go:198 +0xef
  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).GetMatchingResourcesByCurrentId()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resmap/reswrangler.go:176 +0x154
  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).Append()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resmap/reswrangler.go:78 +0x1d
  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).appendAll()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resmap/reswrangler.go:468 +0xf6
  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).AppendAll()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/resmap/reswrangler.go:462 +0x45
  sigs.k8s.io/kustomize/api/internal/accumulator.(*ResAccumulator).AppendAll()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/accumulator/resaccumulator.go:45 +0x45e
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateFile()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:556 +0x437
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:421 +0xed
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:201 +0x9e
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:194 +0x229
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:135 +0x105
  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/internal/target/kusttarget.go:126 +0x4fc
  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run()
      go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/krusty/kustomizer.go:90 +0x4ef

What did you expect to happen?

No data races

How can we reproduce it (as minimally and precisely as possible)?

Run krusty.Run in two or more goroutines with the race detector enabled.

Expected output

No race detected

Actual output

WARNING: DATA RACE

Kustomize version

kyaml 0.18.1

Operating system

Linux

@chlunde chlunde added the kind/bug Categorizes issue or PR as related to a bug. label Nov 21, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Nov 21, 2024
@chlunde
Copy link
Contributor Author

chlunde commented Nov 21, 2024

I think a workaround is to call

 openapi.SchemaForResourceType(kyaml.TypeMeta{}) // https://github.com/kubernetes-sigs/kustomize/issues/5805

Before creating any goroutines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

2 participants