FHIR Chat · c# Validationlibrary not threadsafe · implementers

Stream: implementers

Topic: c# Validationlibrary not threadsafe


view this post on Zulip Jon-Vidar Schneider (Dec 21 2016 at 08:36):

We are using the new c# validation functionality. It seems that the code is not threadsafe. It started when we got some random errors. When running a test running 100000 tasks in parallell we are getting some random errors as well. To improve the performance in our service I have set the Validator object as static. I have attached the output.threadrun.xml

It works fine if I put a lock around validator.Validate(someXmlReader), that ofcourse reduces the performance.

The code for setting up the validator looks like this:
var profilePath = Path.Combine(directoryInfo.FullName) + @"\Definitions";
var coreSource = new CachedResolver(ZipSource.CreateValidationSource());
var cachedResolver = new CachedResolver(new DirectorySource(profilePath, includeSubdirectories: true));
var combinedSource = new MultiResolver(cachedResolver, coreSource);
var settings = ValidationSettings.Default;
settings.EnableXsdValidation = validateXsd;
settings.GenerateSnapshot = true;
settings.Trace = showTrace;
settings.ResourceResolver = combinedSource;
_validator = new Validator(settings);

view this post on Zulip Brian Postlethwaite (Dec 22 2016 at 04:22):

This should probably be moved across to the dotnet thread
https://chat.fhir.org/#narrow/stream/dotnet

view this post on Zulip Martijn Harthoorn (Dec 22 2016 at 12:17):

@Jon-Vidar Schneider - Thanks for the feedback. We'll make note of it. But beware that the Validator is still an alpha release. There also is a known issue around bi-directional references, which causes a stack overflow.

view this post on Zulip Martijn Harthoorn (Dec 22 2016 at 12:21):

I created an issue of it: https://github.com/ewoutkramer/fhir-net-api/issues/280

view this post on Zulip Jon-Vidar Schneider (Dec 22 2016 at 12:28):

Thank you. We are also getting some other random errors, even not with this threadissue. We are going to disable the validation on our production enviroment until we get a solution for all these errors. Will create issues for them in github.

view this post on Zulip Michel Rutten (Dec 22 2016 at 15:23):

Please note that the FHIR .NET API validator is still under development and not yet ready for production environments. For example, slicing validation needs some more work, as well as the interaction with the snapshot generator. Also the validator still needs to detect and handle endless recursion (e.g. Organization.partOf => Organization). Feel free to evaluate/test the code and submit bugs!

view this post on Zulip Jon-Vidar Schneider (Dec 22 2016 at 15:25):

We will. We are only using it in the development phase so we don't deliver fhir-services that is not valid according to the customized profiles.

view this post on Zulip Brian Postlethwaite (Dec 22 2016 at 23:17):

You can however use the invariant validation code in there, it is quite good.
All the examples pass through it, and i've been using it on our server for some time now.

view this post on Zulip Brian Postlethwaite (Dec 22 2016 at 23:18):

There is a unit test that checks this if you want to see how to use it.

view this post on Zulip Brian Postlethwaite (Dec 22 2016 at 23:18):

(and is in both DSTU2 and STU3)


Last updated: Apr 12 2022 at 19:14 UTC