Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-39456

Cache file store fails if used within a destructor

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.3, 2.5, 2.6
    • Fix Version/s: 2.4.5, 2.5.1
    • Component/s: Caching
    • Labels:
    • Testing Instructions:
      Hide

      Unfortunately it is not possible to test this in core, and not possible to write unit tests for it (unit tests hold onto $CFG as well so you can't unset the global there).
      I'll attach a test script to this issue.
      First hit the script without this patch applied, you'll notice that you get lots of errors and its skrew up your moodledata/cache directory permissions.
      Next delete moodledata/cache directory - its messed up beyond repair now.
      Finally apply the patch and hit the script again.
      You'll notice no more error and no more skrewed up cache directory.

      Show
      Unfortunately it is not possible to test this in core, and not possible to write unit tests for it (unit tests hold onto $CFG as well so you can't unset the global there). I'll attach a test script to this issue. First hit the script without this patch applied, you'll notice that you get lots of errors and its skrew up your moodledata/cache directory permissions. Next delete moodledata/cache directory - its messed up beyond repair now. Finally apply the patch and hit the script again. You'll notice no more error and no more skrewed up cache directory.
    • Affected Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE, MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE
    • Pull Master Branch:
      wip-MDL-39456-m26

      Description

      There is a bug within the cache file store if it is used within a destructor and the cache directory does not exist.
      This situation leads to make_writable_directory being called which results in an error being thrown because $CFG has already been destoryed.

      The solution is to hold onto a reference of $CFG within the file cache.
      PHP destorys objects when there are no more references to them, by holding on a reference of $CFG we can be sure it is available until the file store is no longer needed.

      This bug doesn't exist within core as we don't use caches within destructors, however it will arrive sooner rather than later if possible as it allows for destructors to make delayed writes to a cache and operate more closely to the session mechanisms.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    8/Jul/13