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

HTTP 503 Service Not Available is returned by exceptions and should be 500 instead

XMLWordPrintable

    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • MOODLE_311_STABLE
    • MDL_71012_master
    • Easy
    • Hide
      1. Open the developer tools in your browser (F12), and view the Network tab.
      2. Set $CFG->dataroot to a non-existant directory in config.php and visit your site.
        1. You will see the message "Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.". The Network tab will show the request with a 500 HTTP response code.
      3. Set $CFG->dataroot back to the correct directory.
      4. Set $CFG->dbpass to an incorrect password, and visit your site. You will see the following message. The network tab will show the request with a 500 HTTP status code:

      Error: Database connection failed. It is possible that the database is overloaded or otherwise not running properly. The site administrator should also check that the database details have been correctly specified in config.php

      Show
      Open the developer tools in your browser (F12), and view the Network tab. Set $CFG->dataroot to a non-existant directory in config.php and visit your site. You will see the message "Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.". The Network tab will show the request with a 500 HTTP response code. Set $CFG->dataroot back to the correct directory. Set $CFG->dbpass to an incorrect password, and visit your site. You will see the following message. The network tab will show the request with a 500 HTTP status code: Error: Database connection failed. It is possible that the database is overloaded or otherwise not running properly. The site administrator should also check that the database details have been correctly specified in config.php

      We were trying to set up custom maintenance page, by returning a 503 status code from our web server when we want to turn on maintenance mode, and having our front-end display a custom page when it recieves a 503.

      However, we found that when our web server was not set to return a 503, we were still seeing the maintenance page. It turned out the page we were trying to view was throwing an exception, and Moodle's exception handler (via bootstrap_renderer::early_error) was returning a 503, triggering our front-end to show the maintenance page, and preventing us from seeing the error message.

      According to The standard, 503 is:

      503 Service Unavailable
      The server cannot handle the request (because it is overloaded or down for maintenance). Generally, this is a temporary state.

      I believe that Moodle's use of this code for generic exceptions is incorrect. The fact that Moodle is generating exceptions shows that the service is available, but there is something wrong with it. I believe that Moodle should return a 500 Internal Server Error (and a useful error message) in this case, leaving 503 for its intended purpose.

            marxjohnson Mark Johnson
            marxjohnson Mark Johnson
            Brendan Heywood Brendan Heywood
            Andrew Lyons Andrew Lyons
            Gladys Basiana Gladys Basiana
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 50 minutes
                1h 50m

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