-
Bug
-
Resolution: Fixed
-
High
-
7.19.10, 8.5.2
-
9
-
Severity 3 - Minor
-
3
-
Problem
Export to PDF throws HTTP Error 500, Caused by ConcurrentModificationException, when more than one request is done at the same time.
Environment
Steps to Reproduce
- Have a Confluence instance
- Have two or more users requesting the same page to be exported to PDF at the same time.
- Or automate the process of exporting pages having the same page listed multiple times.
Expected Results
All users download the PDF file with page export.
Actual Results
Confluence throws HTTP Error 500. After the first error is not possible to export any other pages to PDF.
In access logs, it is possible to see the requests that happened at the same time.
[30/Aug/2023:12:02:26 +0000] test 10.56.122.50 curl/7.87.0 10.56.122.50 GET GET /confluence/spaces/flyingpdf/pdfpageexport.action?pageId=184071 HTTP/1.1 61743 500 http-nio2-8090-exec-505 184 132 [30/Aug/2023:12:02:26 +0000] test 10.57.148.97 curl/7.87.0 10.57.148.97 GET GET /confluence/spaces/flyingpdf/pdfpageexport.action?pageId=184071 HTTP/1.1 61743 500 http-nio2-8090-exec-410 213 164 [30/Aug/2023:12:02:26 +0000] test 10.57.148.82 curl/7.87.0 10.57.148.82 GET GET /confluence/spaces/flyingpdf/pdfpageexport.action?pageId=184071 HTTP/1.1 61743 500 http-nio2-8090-exec-331 136 88
From the Confluence error, we can see the following:
caused by: java.lang.RuntimeException: com.atlassian.confluence.importexport.ImportExportException: Failure while rendering the /templates/extra/pdfexport/completeexport.vm at com.atlassian.confluence.extra.flyingpdf.sandbox.SandboxPdfExporterService.createDocument(SandboxPdfExporterService.java:310) ... caused by: com.atlassian.confluence.importexport.ImportExportException: Failure while rendering the /templates/extra/pdfexport/completeexport.vm at com.atlassian.confluence.extra.flyingpdf.html.RenderedXhtmlBuilder.createCompleteExportHtml(RenderedXhtmlBuilder.java:319) ... caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getResources' in class com.atlassian.confluence.extra.flyingpdf.impl.PdfResourceManager threw exception java.util.ConcurrentModificationException at /templates/extra/pdfexport/completeexport.vm[line 7, column 30] at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:342) ... caused by: java.util.ConcurrentModificationException at java.base/java.util.ArrayDeque.nonNullElementAt(ArrayDeque.java:271)
Checking the stack trace until we find the getResources we can see the following:
Caused by: java.util.ConcurrentModificationException at java.base/java.util.ArrayDeque.nonNullElementAt(ArrayDeque.java:271) at java.base/java.util.ArrayDeque$DeqIterator.next(ArrayDeque.java:701) at java.base/java.util.AbstractCollection.addAll(AbstractCollection.java:351) at java.base/java.util.LinkedHashSet.<init>(LinkedHashSet.java:169) at com.atlassian.plugin.webresource.models.RawRequest.getIncluded(RawRequest.java:282) at com.atlassian.plugin.webresource.impl.RequestState.getIncluded(RequestState.java:164) at java.base/java.util.Optional.map(Optional.java:265) at com.atlassian.plugin.webresource.impl.helpers.url.ResourceUrlGenerator.generate(ResourceUrlGenerator.java:31) at com.atlassian.plugin.webresource.assembler.DefaultWebResourceSetBuilder.buildDependenciesByPhase(DefaultWebResourceSetBuilder.java:177) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at com.atlassian.plugin.webresource.assembler.DefaultWebResourceSetBuilder.build(DefaultWebResourceSetBuilder.java:158) at com.atlassian.plugin.webresource.assembler.DefaultAssembledResources.peek(DefaultAssembledResources.java:56) at com.atlassian.confluence.extra.flyingpdf.impl.PdfResourceManager.getResources(PdfResourceManager.java:97)
Workaround
Restart Confluence to restore the Export PDF functionality.
There is no workaround to prevent the ConcurrentModificationException from happening.