Skip to content

Concurrency Support #9

Open
@marwan-at-work

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!

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