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

Release the task runner lock before throwing exception

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      To test this we need to simulate a high concurrency for a 'core_cron' lock. The easiest way to do that is to hack the code.

      1. Install testtasks:

        git clone https://github.com/catalyst/moodle-tool_testtasks admin/tool/testtasks
        

      2. Queue a number of tasks:

        php admin/tool/testtasks/cli/queue_adhoc_tasks.php -d=5 -n=50 
        

      3. Open lib/classes/task/manager.php in your editor, find the get_next_adhoc_task function and just before the foreach ($records as $record) line add following:

        sleep(20);
        

      4. Open two terminal windows
      5. In the first run:

        php admin/cli/cron.php
        

      6. Wait a couple of seconds and then, in the second terminal, run:

        php admin/cli/cron.php
        

        1. Confirm, that `locktimeout` exception is thrown by the second cron:

          !!! The operation timed out while waiting for a lock. !!!
          

        2. Confirm, that unreleased lock exception has not been thrown:

          Uncaught coding_exception: Coding error detected, it must be fixed by a programmer: A lock was created but not released at...
          

      7. Run adhoc_task.php from the second terminal:

        php admin/tool/task/cli/adhoc_task.php --execute
        

        ## Confirm, that `locktimeout` exception is thrown by adhoc_task.php:

        !!! The operation timed out while waiting for a lock. !!!
        

        1. Confirm, that unreleased lock exception has not been thrown:
      Show
      To test this we need to simulate a high concurrency for a 'core_cron' lock. The easiest way to do that is to hack the code. Install testtasks: git clone https://github.com/catalyst/moodle-tool_testtasks admin/tool/testtasks Queue a number of tasks: php admin/tool/testtasks/cli/queue_adhoc_tasks.php -d=5 -n=50 Open lib/classes/task/manager.php in your editor, find the get_next_adhoc_task function and just before the foreach ($records as $record) line add following: sleep(20); Open two terminal windows In the first run: php admin/cli/cron.php Wait a couple of seconds and then, in the second terminal, run: php admin/cli/cron.php Confirm , that `locktimeout` exception is thrown by the second cron: !!! The operation timed out while waiting for a lock. !!! Confirm , that unreleased lock exception has not been thrown: Uncaught coding_exception: Coding error detected, it must be fixed by a programmer: A lock was created but not released at... Run adhoc_task.php from the second terminal: php admin/tool/task/cli/adhoc_task.php --execute ##  Confirm , that `locktimeout` exception is thrown by adhoc_task.php: !!! The operation timed out while waiting for a lock. !!! Confirm , that unreleased lock exception has not been thrown:
    • Affected Branches:
      MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_37_STABLE, MOODLE_38_STABLE
    • Pull from Repository:
    • Pull 3.7 Branch:
      MOODLE_37_MDL-67485
    • Pull 3.8 Branch:
      MOODLE_38_MDL-67485
    • Pull Master Branch:
      master_MDL-67485

      Description

      Cron task should release the scheduled and adhoc task runner lock before throwing `locktimeout` exception.

      This will prevent appearing of unnecessary `A lock was created but not released` exceptions and missing `locktimeout` ones in cron logs when task runners can not acquire 'core_cron' lock.

       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mikhailgolenkov Mikhail Golenkov
              Reporter:
              mikhailgolenkov Mikhail Golenkov
              Peer reviewer:
              Brendan Heywood
              Integrator:
              Andrew Nicols
              Tester:
              Janelle Barcega
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/Jan/20

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 3 hours, 30 minutes
                  3h 30m