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

Release the task runner lock before throwing exception

XMLWordPrintable

    • MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • MOODLE_37_STABLE, MOODLE_38_STABLE
    • master_MDL-67485
    • 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:

      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.

       

       

            mikhailgolenkov Misha Golenkov
            mikhailgolenkov Misha Golenkov
            Brendan Heywood Brendan Heywood
            Andrew Lyons Andrew Lyons
            Janelle Barcega Janelle Barcega
            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 - 3 hours, 30 minutes
                3h 30m

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