This issue has been created
There is 1 update, 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-03ba15c5-aaff-42d9-91ba-a509983158ec XWIKI-22215 Open

XWikiDocument#getPreparedXDOM can run the preparation on the same XDOM instance in several threads

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-ce7b5ddb-eec0-4425-874b-21fe8a51f777 Thomas Mortagne created this issue on 06/Jun/24 18:08
 
Summary: XWikiDocument#getPreparedXDOM can run the preparation on the same XDOM instance in several threads
Issue Type: cid:jira-generated-image-avatar-03ba15c5-aaff-42d9-91ba-a509983158ec Bug
Affects Versions: 16.3.0-rc-1
Assignee: Unassigned
Components: Old Core
Created: 06/Jun/24 18:08
Priority: cid:jira-generated-image-static-major-11d73448-831e-4db7-a4a4-cefe802e3563 Major
Reporter: Thomas Mortagne
Description:

I can think of two things:

  • the ideal for performance would probably be to add some read/write locking in getPreparedXDOM() to avoid preparing the content several times
  • the other possibility is to clone the this.xdomCache before preparing it, simpler and getXDOM() won't return a half prepared XDOM but cost a bit more
 
 

1 update

 
cid:jira-generated-image-avatar-ce7b5ddb-eec0-4425-874b-21fe8a51f777 Changes by Thomas Mortagne on 06/Jun/24 18:14
 
Description: Consider the following operations on an instance of XWikiDocument where
xdomCachePrepareDate and xdomCache are initially null.

* Thread 1 calls {{getXDOM()}}. {{this.xdomCache = parseContentNoException();}} is executed.
* Thread 1 calls {{getPreparedXDOM()}} and starts calling {{getMacroTransformation().prepare(xdom)}};
* Thread 2 also calls {{getPreparedXDOM()}} and also calls {{getMacroTransformation().prepare(xdom);}} as {{xdomCachePrepareDate}} is still {{null}}

I can think of two things:

* the ideal for performance would probably be to add some read/write locking in
` getPreparedXDOM() ` to avoid preparing the content several times
* the other possibility is to clone the
` this.xdomCache ` before preparing it, simpler and ` getXDOM() ` won't return a half prepared XDOM but cost a bit more
 
 

1 comment

 
cid:jira-generated-image-avatar-8837f090-2b81-4ea0-ab11-61d934fbf727 Michael Hamann on 06/Jun/24 18:12
 

I think there is not only the risk of returning a half prepared XDOM but there is also the risk of cloning an attribute map while it is modified which shouldn't be supported (might result in a concurrent modification exception I think). Therefore, I think the XDOM needs to be cloned before it is modified.