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

ToVersionless should only call add to scheme once in a program's lifetime #137

Closed
maxsmythe opened this issue Sep 23, 2021 · 0 comments · Fixed by #138
Closed

ToVersionless should only call add to scheme once in a program's lifetime #137

maxsmythe opened this issue Sep 23, 2021 · 0 comments · Fixed by #138

Comments

@maxsmythe
Copy link
Contributor

Maybe use sync.Once?

julianKatz added a commit to julianKatz/frameworks that referenced this issue Sep 28, 2021
In the building of `gator` github.com/willbeason found that the usage of
a shared Scheme amongst multiple sub-packages of pkg/apis/templates was
not thread safe.  An internal map within the Scheme was experiencing a
simultaneous read and write.

Instantiating the scheme in a super-package and using it in the
sub-packages required the creation of a circular dependency, as the
super-package needed the contents of the sub-package to create a
functioning scheme that could convert between sub-package types.  This
was previously solved by adding sub-package contents to the scheme at
scheme-usage-time, but this yielded the race condition on the map.

This PR moves most of the core logic into a separate package: pkg/schema

To prevent a circular dependency, a *runtime.Scheme is passed from
consumer packages to this new package's function call.

These schemes are instantiated once in the consumer packages and the
output of pkg/schema is stored at consumer package init() time to
prevent unnecessary re-calculation.

Fixes open-policy-agent#137

Signed-off-by: juliankatz <juliankatz@google.com>
julianKatz added a commit that referenced this issue Oct 1, 2021
In the building of `gator` github.com/willbeason found that the usage of
a shared Scheme amongst multiple sub-packages of pkg/apis/templates was
not thread safe.  An internal map within the Scheme was experiencing a
simultaneous read and write.

Instantiating the scheme in a super-package and using it in the
sub-packages required the creation of a circular dependency, as the
super-package needed the contents of the sub-package to create a
functioning scheme that could convert between sub-package types.  This
was previously solved by adding sub-package contents to the scheme at
scheme-usage-time, but this yielded the race condition on the map.

This PR moves most of the core logic into a separate package: pkg/schema

To prevent a circular dependency, a *runtime.Scheme is passed from
consumer packages to this new package's function call.

These schemes are instantiated once in the consumer packages and the
output of pkg/schema is stored at consumer package init() time to
prevent unnecessary re-calculation.

Fixes #137

Signed-off-by: juliankatz <juliankatz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant