Skip to content

Concurrency Support #9

Description

@marwan-at-work

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions