Uploaded image for project: 'Moodle app'
  1. Moodle app
  2. MOBILE-4119

Race condition on handlers update

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.0.1
    • Synchronization
    • MOODLE_400_STABLE

      With the current implementation, when subsequent handler updates are triggered the initial update is reused. This is creating a race condition when the change that caused a subsequent update has not been used in the initial update.

      You can look at the example below for more details, but this can potentially result in bugs whenever more than one update is triggered. In particular, application startup is very susceptible from suffering this, and this has already manifested during MOBILE-4025 where this problem was discovered.

      Example:

      Imagine we have a handler that uses the a fictional site property called "secret number" like this:

      async isEnabled(siteId: string): Promise<boolean> {
          const site = await CoreSites.getSite(siteId);
          const secretNumber = await site.getSecretNumber();
          const isValid = await this.validateSecretNumber(secretNumber);
       
          return isValid;
      }
      

      And imagine that this validateSecretNumber method calls an external API, so it can take several seconds to resolve.

      If updating this secret number triggered handler updates, and we run the following code, the end state is likely to be wrong because the handler will be updated only using the initial secret number:

      site.setSecretNumber(0); // invalid number
       
      // a short while after... (not long enough for validateSecretNumber to resolve)
       
      site.setSecretNumber(42); // valid number!
      

            Unassigned Unassigned
            noeldemartin Noel De Martin
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.