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

Fix variable values thread safety in pure mode #183

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bertrand-lorentz
Copy link
Contributor

@bertrand-lorentz bertrand-lorentz commented Nov 5, 2024

Fix issue #182 by storing variable values in a ThreadLocal map, and add a unit test to check for this.

This might not be a perfect fix, but it seems to do the trick.

After this change, the compiled XPaths for the variable values are still potentially used from multiple threads, and XPathExpression is indicated as not being thread-safe.
But I did not see any easy way to adress this, and this does not seem to cause any problems.

This test currently fails because the value of the "var" variable" set
by one thread is overwritten by the other thread.
Theoretically this test would fail or not depending on how the 2 threads
are executed and interweaved. But it seems to always fail, so no further
complication is added for now.
To ensure that variable values are not overwritten when different XML
are validated on separate threads, store the variable values in aborts
ThreadLocal map.

Fixes issue phax#182.
@bertrand-lorentz
Copy link
Contributor Author

@phax : Any chance you could have a look at this PR ?
It's be useful to have your opinion on this fix.

@phax
Copy link
Owner

phax commented Dec 2, 2024

I will try to understand and crosscheck during the week

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

Successfully merging this pull request may close these issues.

2 participants