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

Concurrency Support #9

Open
marwan-at-work opened this issue Feb 2, 2021 · 0 comments · May be fixed by xeipuuv/gojsonschema#323 or xeipuuv/gojsonschema#324
Open

Concurrency Support #9

marwan-at-work opened this issue Feb 2, 2021 · 0 comments · May be fixed by xeipuuv/gojsonschema#323 or xeipuuv/gojsonschema#324

Comments

@marwan-at-work
Copy link

marwan-at-work commented Feb 2, 2021

Hi there,
I noticed that I cannot concurrently validate a payload against a schema even though all of my schemas were pre-loaded.

To reproduce, concurrently run the following code:

sl := gojsonschema.NewSchemaLoader()
sl.AddSchemas(...)
schema, err = sl.Compile(gojsonschema.NewReferenceLoader(...))
if err != nil {
  panic(err)
}
docLoader := gojsonschema.NewBytesLoader(body)
result, err := schema.Validate(docLoader)
if err != nil {
  panic(err)
}
if !result.Valid() {
  for i, err := range result.Errors() {
    fmt.Println(err)
  }
}

I see two solutions here:

Add a mutex around the inner map, or create a Clone() function so that if a user wants to concurrently validate things, they need to clone the schema loader first.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant