Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-19737

GitWorkTreeBuilder API failing for external Mesh when calling execute in an asynchronous thread

XMLWordPrintable

      Issue Summary

      When using the GitWorkTreeBuilder API with repositories stored in an external Mesh, the GitWorkTreeBuilder#execute(GitWorkTreeCallback<T>) method may fail when run in an asynchronous thread. This failure is caused by a bug in the API's logic for routing RPC calls to a Mesh node. Specifically, if the execute method is called asynchronously, any work tree commands within the callback might be routed to a Mesh node that does not have the work tree, resulting in a command failure.

      Note that the issue is intermittent because, at times, the requests are correctly routed to the appropriate Mesh node, allowing the commands to succeed. Also, this issue only occurs for repositories stored in external Mesh. This does not affect repositories that are managed locally by the Mesh sidecar.

      Steps to Reproduce

      The issue can be replicated by calling the execute method in an asynchronous thread as follows:

      // Initialize the GitWorkTreeBuilder
      GitWorkTreeBuilder workTreeBuilder = workTreeBuilderFactory.builder(repository)
              .commit("6053a1eaa1c009dd11092d09a72f3c41af1b59ad")
              .checkoutType(GitCheckoutType.NONE);
      
      // Use an ExecutorService to simulate asynchronous execution
      ExecutorService executorService = Executors.newSingleThreadExecutor();
      
      // Call the execute method in a separate thread
      executorService.execute(() -> {
          workTreeBuilder.execute(workTree -> {
              // Any command executed on the workTree object
              // within this callback may fail if routed to
              // an incorrect Mesh node
          });
      });
      

      Expected Results

      The execute method finishes successfully with no errors.

      Actual Results

      The execute method may fail and throw the following error in the logs.

      com.atlassian.bitbucket.repository.NoSuchRepositoryException: There is no repository with ID wt/5
      Suppressed: java.lang.IllegalArgumentException: The work tree was not found, it may have expired or been deleted
      

      Workaround

      Currently there is no known workaround for this behavior. A workaround will be added here when available

              mgoyal2@atlassian.com Manish
              74d6667aa35c Josh Aguilar
              Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: