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

Race condition on handlers update

    XMLWordPrintable

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 4.0.1
    • None
    • Synchronization
    • MOODLE_400_STABLE

    Description

      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!
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated: