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

Fixed race condition in schema validation #2653

Merged
merged 2 commits into from
Oct 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ludwig/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#

from functools import lru_cache
from threading import Lock

from jsonschema import Draft7Validator, validate
from jsonschema.validators import extend
Expand All @@ -40,6 +41,8 @@
from ludwig.schema.preprocessing import get_preprocessing_jsonschema
from ludwig.schema.trainer import get_model_type_jsonschema, get_trainer_jsonschema

VALIDATION_LOCK = Lock()


@lru_cache(maxsize=2)
def get_schema(model_type: str):
Expand Down Expand Up @@ -82,4 +85,7 @@ def validate_config(config):
updated_config = upgrade_to_latest_version(config)
model_type = updated_config.get(MODEL_TYPE, MODEL_ECD)

validate(instance=updated_config, schema=get_schema(model_type), cls=get_validator())
with VALIDATION_LOCK:
# There is a race condition during schema validation that can cause the marshmallow schema class to
# be missing during validation if more than one thread is trying to validate at once.
validate(instance=updated_config, schema=get_schema(model_type), cls=get_validator())