Confluence search fail with HTTP 500 error
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
When performing a search within Confluence while using the search box located on the top right of the screen, a spinning wheel appear and a result isn't returned.
Diagnosis
Checking the browser logs (for example: in Chrome, F12 or View > Developer > Developer Tools > Network tab), it's possible to see a HTTP 500 Error:
If you cross-check this error with the atlassian-confluence.logs, it's possible to see the following error:
2020-07-17 16:37:45,210 ERROR [ajp-nio-127.0.0.1-8009-exec-208] [[Standalone].[localhost].[/].[file-server]] log Servlet.service() for servlet [file-server] threw exception
-- referer: https://XXXXXXXX | url: /s/XXXXXXXX-CDN/XX/XXX/XXXXX/XXXXXXX/_/download/contextbatch/js/confluence-search-ui-plugin-main,-_super/batch.js | traceId: XXXXXX | userName: XXXXX
java.lang.StackOverflowError
at java.util.regex.Pattern$Branch.match(Pattern.java:4618)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4672)
at java.util.regex.Pattern$Branch.match(Pattern.java:4618)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4672)
at java.util.regex.Pattern$Loop.match(Pattern.java:4799)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4731)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4582)
at java.util.regex.Pattern$BmpCharProperty.match(Pattern.java:3812)
The lines related to java.util.regex.Pattern repeat for hundreds of lines.
Cause
Every thread in a Java application has a stack that's used to save the return address between method calls and method call arguments amongst other things. In scenarios where a thread is processing a large data structure, it's possible that the system can run out of memory for the stack. In this case, where the Confluence site contained a high volume of content, Confluence fails to complete the search.
Resolution
Increase the Java parameter -Xss to a higher value. The default value for a Linux 64 bit system is 1024K. Increasing this to 2MB should be enough to allow the search to complete: -Xss2m. To take effect, Confluence will need to be restarted.
Memory consumption
If the issue continue to happens, it's possible to increase it even further. However, this will increase the memory consumption by the JVM since each Thread will be able to use more memory. Therefore, an increase in the Java Heap may also be necessary.
Since the default Xss value can differ between operating systems and Java versions, please run the following command to determine its current value:
java -XX:+PrintFlagsFinal -version | grep ThreadStackSize