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

Watchers added through API (WatcherManager) can't be removed through UI

      Summary

      If using a post-function that mutates watchers, it can cause the watcher counts to get out of sync. This leads to being unable to remove watchers unless there is more than 1 watcher on the issue.

      Steps to Reproduce

      1. Install the JIRA Workflow Toolbox add-on.
      2. Configure it to add watchers no issue transition.
      3. Add a watcher normally.
      4. Transition an issue and add a watcher during that transition.
      5. Attempt to remove both watchers.

      Expected Results

      Both watchers can be removed.

      Actual Results

      Only one can be (the first one). If there's only one left it can't be.

      Notes

      This is not caused by the plugin as it uses our API - the problem is when the API is called during transition:

      1. In com.atlassian.jira.issue.watchers.DefaultWatcherManager#adjustWatchCount (this is what the API gets into) it creates a cloned issue and updates the watcher count and persists that. This is fine for com.atlassian.jira.web.action.issue.VoteOrWatchIssue#doExecute because nothing happens after that.
      2. However in the workflow transition, com.atlassian.jira.workflow.OSWorkflowManager#doWorkflowActionInsideTxn, it's quite different:
                    try {
                        wf.doAction(wfid, from.getAction(), inputs);
        
                        // save the issue updates - the generate change history function stores the issue as well, but if it has been modified by some post functions
                        // after that we need to store the issue again.
                        issue.store();
        
                        // commit the TX
                        txn.commit();
        
      3. The problem is inside the workflow, we perform the watch update, with the updated issue count on jiraissue, however then we store the issue again inside the transition method and it overwrites the change. Doh.

            [JRASERVER-45574] Watchers added through API (WatcherManager) can't be removed through UI

            Hi All, since Atlassian did not fix this bug by now (already 8 years)  I decided to develop a soltution for this.

             

            This solution has been tested with listeners but shuold work with post function as well

            The Trick is very easy just wrap the watchManager.startWatching(user, issue) into a TimerTask

            Using Scriptrunner:

             

             

             

             

            ...
            TimerTask task = new TimerTask() {
             public void run() { 
                watcherManager.startWatching(user, issue)
             }
            }
            Timer timer = new Timer("Timer");
            long delay = 1L;
            timer.schedule(task, delay);
            ---
              

             

             

            This way I am able to delete the added user manually via GUI

             

            Cheers

            Heiko Gerlach

            Nexus AG

            Heiko Gerlach added a comment - Hi All, since Atlassian did not fix this bug by now (already 8 years)  I decided to develop a soltution for this.   This solution has been tested with listeners but shuold work with post function as well The Trick is very easy just wrap the watchManager.startWatching(user, issue) into a TimerTask Using Scriptrunner:         ... TimerTask task = new TimerTask() { public void run() { watcherManager.startWatching(user, issue) } } Timer timer = new Timer( "Timer" ); long delay = 1L; timer.schedule(task, delay); ---     This way I am able to delete the added user manually via GUI   Cheers Heiko Gerlach Nexus AG

            Just FYI, when this happens, the following record is logged:
            Watcher count for issue 'INC-48' is out of sync. Updating from '1' to '2'.

            2023-05-31 10:55:31,423+0200 http-nio-8080-exec-14647 WARN radek.janata 655x67344712x5 y9tulx 10.10.103.76,10.1.86.16 /rest/api/2/issue/INC-48/comment [c.b.j.event.issue.FixWatcherCounterListener] Watcher count for issue 'INC-48' is out of sync. Updating from '1' to '2'.

            Radek Janata added a comment - Just FYI, when this happens, the following record is logged: Watcher count for issue 'INC-48' is out of sync. Updating from '1' to '2'. 2023-05-31 10:55:31,423+0200 http-nio-8080-exec-14647 WARN radek.janata 655x67344712x5 y9tulx 10.10.103.76,10.1.86.16 /rest/api/2/issue/INC-48/comment [c.b.j.event.issue.FixWatcherCounterListener] Watcher count for issue 'INC-48' is out of sync. Updating from '1' to '2'.

            our team got impacted due to this bug, please plan to fix this near future. 

            Villarasan added a comment - our team got impacted due to this bug, please plan to fix this near future. 

            Nikola Bornová added a comment - - edited

            Confirmed  workaround from Oleksii works (thanks!).

            Although it's only workaround and it isn't usable if you have hundreds of affected issues - this should be solved by Atlassian.

            (Jira Server 8.3.2)

            Nikola Bornová added a comment - - edited Confirmed  workaround from Oleksii works (thanks!). Although it's only workaround and it isn't usable if you have hundreds of affected issues - this should be solved by Atlassian. (Jira Server 8.3.2)

            Stefan, Oleksii's workaround worked for me (~20 issues), but with so many issues affected you might be better off directly modifying the database. This issue has been around for almost 4 years... I don't think they're in any hurry to fix it.

            joe.chlimoun@l3harris.com added a comment - Stefan, Oleksii's workaround worked for me (~20 issues), but with so many issues affected you might be better off directly modifying the database. This issue has been around for almost 4 years... I don't think they're in any hurry to fix it.

            This bug also affects Jira 8.1.0

            Soporte Excentia added a comment - This bug also affects Jira 8.1.0

            Stefan Reich added a comment - - edited

            We are also affected;
            Our "custom watchers" get added through groovy scripts (Adaptivist ScriptRunner) using the WatcherManager interface...

            Update: As meddling with the underlying database is discouraged, we have no way to fix this problem. Currently we have 2462 affected issues...

            Stefan Reich added a comment - - edited We are also affected; Our "custom watchers" get added through groovy scripts (Adaptivist ScriptRunner) using the WatcherManager interface... Update: As meddling with the underlying database is discouraged, we have no way to fix this problem. Currently we have 2462 affected issues...

            Dear all,

            This bug affects Jira 7.8.0 too.

            Hope Atlassian development team fix this soon :S

            Soporte Excentia added a comment - Dear all, This bug affects Jira 7.8.0 too. Hope Atlassian development team fix this soon :S

            In this discussion thread <https://community.developer.atlassian.com/t/calling-watcherservice-addwatcher-means-you-can-never-drop-the-number-of-issue-watchers> I am seeing the same behavior that Fidel describes a few posts up: it's not that the specific user being added through the API can't be removed; it's just that the number of watchers added through the API becomes the minimum number of watchers on the issue. Therefore, you can remove a specific user by first adding someone else to take their place.

            Andrew Pane added a comment - In this discussion thread < https://community.developer.atlassian.com/t/calling-watcherservice-addwatcher-means-you-can-never-drop-the-number-of-issue-watchers > I am seeing the same behavior that Fidel describes a few posts up: it's not that the specific user being added through the API can't be removed; it's just that the number of watchers added through the API becomes the minimum number of watchers on the issue. Therefore, you can remove a specific user by first adding someone else to take their place.

            workaround that works for me: remove user through UI, instantly add same user again through UI, and then remove user through UI again

            or (me being the user) stop watching, start watching, stop watching again.

             

            Oleksii Gnatkevych added a comment - workaround that works for me: remove user through UI, instantly add same user again through UI, and then remove user through UI again or (me being the user) stop watching, start watching, stop watching again.  

              Unassigned Unassigned
              799e74df6e6b Fidel Castro
              Affected customers:
              82 This affects my team
              Watchers:
              74 Start watching this issue

                Created:
                Updated: