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

styles_debug returns 404s on busy sites

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.6
    • Fix Version/s: 2.4
    • Component/s: Themes
    • Labels:
    • Testing Instructions:
      Hide

      1/ enable themedesigner mode
      2/ run the attached jmeter script (modify it to match your site address)
      3/ visit site using normal browser and make sure all styles load
      4/ modify CSS in source code
      5/ verify the change appears in browser

      Show
      1/ enable themedesigner mode 2/ run the attached jmeter script (modify it to match your site address) 3/ visit site using normal browser and make sure all styles load 4/ modify CSS in source code 5/ verify the change appears in browser
    • Affected Branches:
      MOODLE_21_STABLE
    • Fixed Branches:
      MOODLE_24_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      w28_MDL-34057_m24_styledebug

      Description

      Was accidentally load testing with theme designer mode turned on, but it highlighted a potential issue.

      I was occasionally getting 404s returned by styles_debug.php and these seem to stem from:

      if (!file_exists($candidatesheet)) {
          css_send_css_not_found();
      }

      Looking into the commit that introduced this, I think that it could potentially be a race condition on busy sites.

      The original commit which introduced this was 7829cf7955174a561ea9e1d736085342842cf738 (MDL-21208).

      From the way I read it, the serialized CSS is generated in lib/outputlib.php::css_urls() if the theme revision is -1 (e.g. theme designer mode is on).
      It looks like if the candidate sheet exists but is older than the THEME_DESIGNER_CACHE_LIFETIME (defaults to 4 seconds), then:

      • the existing candidate sheet is ulinked
      • the css content is generated
      • the new candidate sheet is serialized and put in place

      As a result, if multiple requests are hitting a site then there's a potential for:

      • Request to Client A is served
        • css_urls generates the candidatesheet
      • Some content is served to Client A
      • Request to Client B is served 5 seconds later
        • The candidatesheet is stale so unlinked
        • New CSS generation begins
      • Client A starts downloading style sheets
        • canidatesheet does not exist so a styles_debug.php returns a 404
      • Client B's CSS generation completes
        • CSS Content is serialized
        • serialized CSS content written to candidatesheet
      • Client B retrieves content

        Gliffy Diagrams

          Attachments

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  3/Dec/12