Uploaded image for project: 'Jira Server and Data Center'
  1. Jira Server and Data Center
  2. JRASERVER-67202

Documentation: Plugin should call clearRequestCache for JiraAuthenticationContextImpl after execution

    XMLWordPrintable

Details

    • 3
    • 4
    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

    Description

      Problem Definition

      JIRA caches different data in JiraAuthenticationContextImpl for each request in ThreadLocal. That data is cleared after each request by Jira in case of HTTP requests, so there is no problem there.
      When you use com.atlassian.jira.security.JiraAuthenticationContext directly or indirectly from your code in separate thread, you need to clear the cache. In other case you will have thread which leaks ThreadLocal and holds large amount of memory in com.atlassian.jira.bc.issue.search.QueryCacheImpl$QueryCacheLiteralsKey.

      Example of indirect use of JiraAuthenticationContext:

      long hitcount = searchService.searchCount(user, pr.getQuery());
      

      Suggested Solution

      • Create/Update public documentation for developers which references JiraThreadLocalUtil or OffRequestThreadExecutor.
        • Explain use cases of JiraThreadLocalUtil and share examples of proper API method.
      • As a workaround, you will need to add a cache clear somewhere to prevent these objects from accumulating over time. Here's some general docs on this api:
      • An example of how plugin vendor implemented this: TransitionWorkflowExtended.html
           try
           {
               // Execute as specified user
               authenticationContext.setUser(user);
               JiraAuthenticationContextImpl.clearRequestCache();
        
               // We have the workflow transition id.
               // Now we need to process and validate all the fields that can be set during the transition
               WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilAddOnImpl.class);
               workflowTransitionUtil.setIssue(issue);
               workflowTransitionUtil.setAction(actionId);
               workflowTransitionUtil.setParams(params);
        
               // Validate input
               JellyUtils.processErrorCollection(workflowTransitionUtil.validate());
        
               // Progress the issue through workflow
               JellyUtils.processErrorCollection(workflowTransitionUtil.progress());
           }
           finally
           {
               // Restore the user
               authenticationContext.setUser(previousUser);
               JiraAuthenticationContextImpl.clearRequestCache();
           }
        

      Attachments

        Issue Links

          Activity

            People

              tbartyzel Tomasz Bartyzel
              ayakovlev@atlassian.com Andriy Yakovlev [Atlassian]
              Votes:
              6 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated: