Jira Cloud integration lock issue when 403 handling invalidates JiraCloudPermissionsCache - commit indexing and dev-info sync stop permanently

XMLWordPrintable

    • 1
    • Severity 2 - Major

      Issue Summary

      In Bitbucket Data Center 9.4.1 with Jira Cloud integration (Jira site connected via OAuth / Application Tunnel), the Jira Cloud integration can enter a permanent deadlock:

      One thread loads a value into JiraCloudPermissionsCache while holding the cache's per-key lock, and blocks on Promise.claim() without a timeout waiting for the Jira Cloud permissions HTTP response.

      The only httpclient-callbacks thread handles a 403 Forbidden response. The recover callback registered by JiraCloudPermissionsWrapper.checkForForbiddenException runs synchronously on that callback thread and calls JiraCloudPermissionsCache.invalidate() → Cache.remove(). This blocks on the same per-key lock.

      The callback thread is blocked, so no HTTP response completion can be delivered (the pool has only one thread). The permissions future that the lock holder waits on never completes, and the lock is never released.

      Thread dump example:

      • Lock holder — waits forever for the permissions response
        "commit-indexing:thread-3" nid=0x2d114b elapsed=689362s  WAITING (parking)
          - parking to wait for <0x...e2e3e098> (java.util.concurrent.CompletableFuture$Signaller)
          at java.util.concurrent.CompletableFuture.get
          at io.atlassian.util.concurrent.Promises$OfStage.claim(Promises.java:280)
          at c.a.stash.internal.jira.cloud.client.JiraCloudPermissionsCache.fetchPermissions(JiraCloudPermissionsCache.java:58)
          at ...DelegatingCache.lambda$get$1(DelegatingCache.java:193)      <-- per-key ReentrantLock <0x...e2e3ebc8> presumably held here
          at com.google.common.cache.LocalCache$Segment.loadSync
          at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad
          - locked <0x...e2e3df08> (LocalCache$StrongWriteEntry)
          at c.a.stash.internal.jira.cloud.client.JiraCloudPermissionsCache.get
          at c.a.stash.internal.jira.cloud.client.JiraCloudPermissionsWrapper.withPermission
          ...
         
      • The only HTTP callback thread — blocked in 403 handling
          "httpclient-callbacks:thread-203" nid=0x104c38 elapsed=519963s  WAITING (parking)
          - parking to wait for <0x...e2e3ebc8> (ReentrantLock$NonfairSync)
          at ...DelegatingCache.acquireLockFor(DelegatingCache.java:468)
          at ...DelegatingCache.remove(DelegatingCache.java:241)
          at c.a.stash.internal.jira.cloud.client.JiraCloudPermissionsCache.invalidate(JiraCloudPermissionsCache.java:54)
          at c.a.stash.internal.jira.cloud.client.JiraCloudPermissionsWrapper.lambda$checkForForbiddenException$0(JiraCloudPermissionsWrapper.java:52)
          at java.util.concurrent.CompletableFuture.uniExceptionally
          at java.util.concurrent.CompletableFuture.completeExceptionally
          at io.github.resilience4j.circuitbreaker.CircuitBreaker.lambda$decorateCompletionStage...
          ...
         
      • Wait cycle
          commit-indexing:thread-3
          holds   : DelegatingCache per-key lock <e2e3ebc8>  (during cache load)
          waits on: permissions HTTP future <e2e3e098>  -- claim() without timeout
                         ^ completion must be delivered by the httpclient-callbacks pool (1 thread)
        httpclient-callbacks:thread-203
          executing: recover() of a 403 response -> JiraCloudPermissionsCache.invalidate()
          waits on : DelegatingCache per-key lock <e2e3ebc8>   -> held by commit-indexing:thread-3
        

      Steps to Reproduce

      1. Connect Bitbucket DC 9.4.x to a Jira Cloud site.
      2. Make Jira Cloud return 403 to Bitbucket (for example, enable an IP allowlist that excludes Bitbucket's egress IP).
      3. Push commits or update PRs so that a permissions cache load and a 403 dev-info response overlap. Shortening the permissions cache TTL makes the overlap more likely.

      Expected Results

      A 403 invalidates the permissions cache and the operation fails gracefully. Indexing and dev-info sync continue and recover once access is restored.

      Actual Results

      Commit indexing and dev-info sync stop, and refresh permissions and site creation REST calls hang indefinitely. Only a restart recovers.

      Workaround

      Restart Bitbucket, and remove the cause of the 403 (Jira Cloud IP allowlist or proxy configuration)

              Assignee:
              Unassigned
              Reporter:
              Yukinobu Moriya
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: