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

non-thread-safe XPathFactory reused in XpathDirective.FACTORY #82

Closed
rgevaerd opened this issue Aug 5, 2018 · 16 comments
Closed

non-thread-safe XPathFactory reused in XpathDirective.FACTORY #82

rgevaerd opened this issue Aug 5, 2018 · 16 comments
Assignees
Labels

Comments

@rgevaerd
Copy link

rgevaerd commented Aug 5, 2018

I believe this reuse of non-thread-safe object by xembly is causing zerocracy/farm#1167 (comment):

java.lang.ArrayIndexOutOfBoundsException: 8
	at java.util.ArrayList.add(ArrayList.java:459)
	at net.sf.saxon.functions.FunctionLibraryList.addFunctionLibrary(FunctionLibraryList.java:44)
	at net.sf.saxon.Configuration.getBuiltInExtensionLibraryList(Configuration.java:1388)
	at net.sf.saxon.sxpath.AbstractStaticContext.setDefaultFunctionLibrary(AbstractStaticContext.java:127)
	at net.sf.saxon.xpath.JAXPXPathStaticContext.<init>(JAXPXPathStaticContext.java:56)
	at net.sf.saxon.xpath.XPathEvaluator.<init>(XPathEvaluator.java:71)
	at net.sf.saxon.xpath.XPathFactoryImpl.newXPath(XPathFactoryImpl.java:203)
	at org.xembly.XpathDirective.traditional(XpathDirective.java:138)
	at org.xembly.XpathDirective.exec(XpathDirective.java:98)
	at org.xembly.Xembler.apply(Xembler.java:155)
	at org.xembly.Xembler.dom(Xembler.java:210)
	at org.xembly.Xembler.xml(Xembler.java:256)
	at org.xembly.Xembler.xmlQuietly(Xembler.java:221)
	at com.zerocracy.claims.ClaimOut.postTo(ClaimOut.java:127)
	at com.zerocracy.pm.FootprintTest.lambda$addsInThreads$0(FootprintTest.java:88)
	at com.zerocracy.RunsInThreads.lambda$matchesSafely$0(RunsInThreads.java:90)
	at com.jcabi.log.VerboseCallable.call(VerboseCallable.java:173)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at com.jcabi.log.VerboseThreads$Wrap.run(VerboseThreads.java:221)
	at java.lang.Thread.run(Thread.java:745)

As you can see in XPathFactory documentation (https://docs.oracle.com/javase/8/docs/api/javax/xml/xpath/XPathFactory.html), it is not thread-safe and must never be used by more than one thread concurrently.
Xembly stores in the static final attribute XpathDirective.FACTORY an instance of such object and reuses it in many operations. Because of this, any multi-threaded application are subject to suffer misbehavior when using Xembly.
The error above is one example of such misbehavior that may happen when using Xembly in more than one thread. In this case this exception occurs on a race condition when calling Xembler.xmlQuietly on different threads, even with the threads using their own Xembler instance (because xembly internally will reuse the same XPathFactory causing the error).

@0crat
Copy link
Collaborator

0crat commented Aug 5, 2018

@carlosmiranda/z please, pay attention to this issue

@0crat
Copy link
Collaborator

0crat commented Aug 5, 2018

@rgevaerd/z this project will fix the problem faster if you donate a few dollars to it; just click here and pay via Stripe, it's very fast, convenient and appreciated; thanks a lot!

@carlosmiranda
Copy link
Collaborator

@rgevaerd can you revise the description a bit with some more details? What is the problematic code and why?

@rgevaerd
Copy link
Author

rgevaerd commented Aug 6, 2018

@carlosmiranda added more details to the description.

@carlosmiranda
Copy link
Collaborator

@0crat in

@0crat 0crat added the scope label Aug 6, 2018
@0crat
Copy link
Collaborator

0crat commented Aug 6, 2018

@0crat in (here)

@carlosmiranda Job #82 is now in scope, role is DEV

@0crat
Copy link
Collaborator

0crat commented Aug 6, 2018

Bug was reported, see §29: +15 point(s) just awarded to @rgevaerd/z

@0crat
Copy link
Collaborator

0crat commented Aug 6, 2018

@carlosmiranda/z everybody who has role DEV is banned at #82; I won't be able to assign anyone automatically; consider assigning someone manually (as in §19), or invite more people (as in §51), or remove the job from the scope (as in §14)

@carlosmiranda carlosmiranda self-assigned this Aug 10, 2018
@0crat
Copy link
Collaborator

0crat commented Aug 10, 2018

The job #82 assigned to @carlosmiranda/z, here is why; the budget is 30 minutes, see §4; please, read §8 and §9; if the task is not clear, read this and this; there will be a monetary reward for this job

@0crat
Copy link
Collaborator

0crat commented Aug 10, 2018

Manual assignment of issues is discouraged, see §19: -5 point(s) just awarded to @carlosmiranda/z

carlosmiranda pushed a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda pushed a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda added a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda added a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda added a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda added a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda added a commit that referenced this issue Aug 10, 2018
carlosmiranda added a commit to carlosmiranda/xembly that referenced this issue Aug 10, 2018
carlosmiranda added a commit that referenced this issue Aug 10, 2018
@carlosmiranda
Copy link
Collaborator

carlosmiranda commented Aug 10, 2018

@rgevaerd should be fixed in #83, I am working on releasing a patch.

@carlosmiranda
Copy link
Collaborator

@rgevaerd Released as 0.22.1, see https://github.com/yegor256/xembly/releases. Please check and close if all is in order.

@rgevaerd
Copy link
Author

@carlosmiranda Thanks

@0crat
Copy link
Collaborator

0crat commented Aug 11, 2018

Job was finished in 21 hours, bonus for fast delivery is possible (see §36)

@0crat 0crat removed the scope label Aug 11, 2018
@0crat
Copy link
Collaborator

0crat commented Aug 11, 2018

Order was finished: +35 point(s) just awarded to @carlosmiranda/z

@0crat
Copy link
Collaborator

0crat commented Aug 11, 2018

The job #82 is now out of scope

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

No branches or pull requests

3 participants