Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-32032

Autowatch plugin updates issues in an unsafe way

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • High
    • 6.0-OD-12/RC1
    • None
    • None
    • None

    Description

      NOTE: This bug report is for JIRA Server. Using JIRA Cloud? See the corresponding bug report.

      There's a problem with how the autowatch plugin updates issues to update their watch count.

      On receiving created or commented events via the AutoWatchService it calls addWatcher passing in the issue from the event:

       @EventListener
          public void onIssueEvent(final IssueEvent event)
          {
              if (watcherService.isWatchingEnabled())
              {
                  final User user = event.getUser();
                  if (user != null && isEnabled(user) && isAutowatchEvent(event))
                  {
                      watcherService.addWatcher(event.getIssue(), user, user);
                  }
              }
          }
      

      This code then eventually calls:

              Long watches = issue.getLong("watches");
      
              if (watches == null)
              {
                  watches = 0L;
              }
              watches = watches + adjustValue;
      
              if (watches < 0)
              {
                  watches = 0L;
              }
      
              issue.set("watches", watches);
              issue.store();
      
              try
              {
                  indexManager.reIndex(issue);
              }
              catch (final IndexException e)
              {
                  log.error("Exception re-indexing issue " + e, e);
              }
      

      This is bad for serveral reasons:

      • It saves all fields back to the database rather than just 'watches'
      • It uses an issue GV from the event which may be stale at the time of processing
      • It doesn't call the issue update manager to update the issue

      This can lead to weird behaviour if you have other listeners that update issues.

      For example this can happen:

      • User creates issue (default assignee is 'admin')
      • Listener one handles this event and auto-assigns the issue to 'fred'
      • Autowatch listener handles the create and increases the watch count. By doing so it saves all fields which came from the original create event therefore overriding the assignee with 'admin' again

      There's no way to guarantee ordering of events so this is hard to work around. I think this can also lead to concurrent edit issues:

      • User fred comments on issue
      • User barney edits issue priority to 'Critical'
      • Autowatch listener handles fred commented event and increases watchers. At the same time it overrides barney's priority edit with the original priority.

      To fix this we should change the AutoWatch plugin to either use JIRA's issueManager.updateIssue() which does the correct thing, or at the very least create an updateGV copy with only the fields that have to be updated in the DB.

      Attachments

        Issue Links

          Activity

            People

              edalgliesh Eric Dalgliesh
              andreask@atlassian.com Andreas Knecht (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: