Unable to load Pull Request attachments in Bitbucket due to a 500 StackOverflow error

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問


プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

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.

*Fisheye および Crucible は除く

要約

  • Bitbucket requires the Thread Stack Size of your JDK or JRE to be set to 1M. If this value is lower, certain functions might suffer from a stack overflow error
  • This scenario holds true in particular for loading attachments on Pull Requests. 

診断

Clicking on an attachment on a Pull Requests displays a spinner that never loads and a 500 error logged on the server. 

The error message will be similar to this one in bitbucket-atlassian.log:

2021-11-22 13:14:40,215 ERROR [http-nio-7990-exec-2] @1JIO688x794x251x1 11u5omw 10.255.0.1,10.255.0.3 "GET /s/aa4385f70f3ac34990cfaf189753ebdc-CDN/-1109379607/c20da00/n1cn5w/42daffda572964b89e141ed74bc85c02/_/download/contextbatch/js/com.atlassian.bitbucket.server.bitbucket-frontend:@atlaskit-internal_media-viewer,-_super/batch.js HTTP/1.1" o.a.c.c.C.[.[.[.[fileServerServlet] Servlet.service() for servlet [fileServerServlet] threw exception
java.lang.StackOverflowError: null
javax.servlet.ServletException: Servlet execution threw an exception
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:234)
	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
	at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:24)
	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(LifecycleJohnsonServletFilterModuleContainerFilter.java:42)
	at com.atlassian.bitbucket.internal.ratelimit.servlet.filter.RateLimitFilter.doFilter(RateLimitFilter.java:75)
	at com.atlassian.plugins.slack.analytics.SlackAnalyticsFilter.doFilter(SlackAnalyticsFilter.java:35)
	at com.atlassian.troubleshooting.thready.filter.AbstractThreadNamingFilter.doFilter(AbstractThreadNamingFilter.java:46)
	at com.atlassian.stash.internal.spring.lifecycle.LifecycleJohnsonServletFilterModuleContainerFilter.doFilter(
	...
Caused by: java.lang.StackOverflowError: null
	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)
...


This is likely caused by the Thread Stack Size (also know as the -Xss flag) on your JDK or JRE being smaller than 1M, which is the default setting that ships with most JDKs and JREs. This can be easily verified by running the following command:

java -XX:+PrintFlagsFinal -version | grep ThreadStackSize

The output will be similar to this one, where we are interested on the ThreadStackSize result, which in this case is set to 1024 (1M). If the value is lower, than it needs to be increased:

# java -XX:+PrintFlagsFinal -version | grep ThreadStackSize
     intx CompilerThreadStackSize                  = 1024                                   {pd product} {default}
     intx ThreadStackSize                          = 1024                                   {pd product} {default}
     intx VMThreadStackSize                        = 1024                                   {pd product} {default}
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu220.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu220.04, mixed mode, sharing)


原因

The Xss (Thread Stack Size) flag on the JDK or JRE is set lower than the default setting, causing a stack overflow error on Bitbucket when loading certain actions.

Some JDKs or JREs could be set to use 512k as their default size, instead of 1M, which is what we recommend for Bitbucket. 

ソリューション

To resolve this issue, we can setup Bitbucket to use 1M for its Thread Stack Size during startup:

  • Update the JVM_SUPPORT_RECOMMENDED_ARGS (in the _start-webapp.sh / _start-webapp.bat file) on each application node by adding an entry for -Xss. The line would look similar to this:

    JVM_SUPPORT_RECOMMENDED_ARGS = -Xss1M
  • If you already have multiple entries under JVM_SUPPORT_RECOMMENDED_ARGS, simply add -Xss1M at the end of the line
  • Restart each Bitbucket application node after making this change
  • After all application nodes are update, you should be able to preview attachments again


最終更新日 2022 年 11 月 23 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.