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

Forum mailings and maintenance jobs fails with "Suspended account" exception

XMLWordPrintable

      Synopsis

      This has been originally reported as a problem on moodle.org after the site was upgraded to 3.7. Moodle stopped sending email notifications to users subscribed to the site forums. Running the task manually led to a failure:

      $ sudo -u www-data php admin/tool/task/cli/schedule_task.php --execute='\mod_forum\task\cron_task'
      [PID 13107] Execute scheduled task: Forum mailings and maintenance jobs (mod_forum\task\cron_task)
      [PID 13107] Removing old digest records from 7 days ago.
      [PID 13107] Removed all old digest records.
      [PID 13107] Fetching unmailed posts.
      [PID 13107] Done
      [PID 13107] Processing post information
      [PID 13107] Processed 148 posts
      [PID 13107] Filling caches
      [PID 13107]   Filling course cache
      [PID 13107]   Done
      [PID 13107]   Filling forum cache
      [PID 13107]   Done
      [PID 13107]   Filling discussion cache
      [PID 13107]   Done
      [PID 13107]   Filling user subscription cache
      [PID 13107]   Done
      [PID 13107]   Filling digest cache
      [PID 13107]   Done
      [PID 13107] All caches filled
      [PID 13107] Queueing user tasks.
      [PID 13107]   Processing 6563 users
      [PID 13107]     Queued 0 digests and 5 messages for 1174932
      [PID 13107]     Queued 0 digests and 51 messages for 12568
      [PID 13107]     Queued 0 digests and 18 messages for 1180476
      [PID 13107]     Queued 0 digests and 23 messages for 1244321
      [PID 13107]     Queued 0 digests and 0 messages for 2628319
      [PID 13107]     Queued 0 digests and 0 messages for 553043
      [PID 13107]     Queued 0 digests and 0 messages for 965252
      [PID 13107]     Queued 0 digests and 0 messages for 1070092
      [PID 13107]     Queued 1 digests and 0 messages for 63444
      [PID 13107]     Queued 0 digests and 0 messages for 2227622
      [PID 13107]     Queued 0 digests and 18 messages for 15479
      [PID 13107]     Queued 0 digests and 26 messages for 827446
      [PID 13107]     Queued 0 digests and 23 messages for 391245
      [PID 13107]     Queued 0 digests and 0 messages for 1818686
      [PID 13107]     Queued 0 digests and 29 messages for 276376
      [PID 13107]     Queued 0 digests and 18 messages for 1146882
      [PID 13107]     Queued 0 digests and 0 messages for 1795164
      [PID 13107]     Queued 0 digests and 0 messages for 120894
      [PID 13107]     Queued 0 digests and 0 messages for 2637212
      [PID 13107]     Queued 1 digests and 0 messages for 200812
      [PID 13107]     Queued 0 digests and 3 messages for 890398
      [PID 13107]     Queued 0 digests and 0 messages for 1191309
      [PID 13107]     Queued 0 digests and 8 messages for 150934
      [PID 13107]     Queued 1 digests and 0 messages for 429480
      [PID 13107]     Queued 0 digests and 22 messages for 245443
      [PID 13107]     Queued 0 digests and 0 messages for 2597442
      [PID 13107]     Queued 0 digests and 0 messages for 2177440
      [PID 13107]     Queued 0 digests and 0 messages for 1391647
      [PID 13107]     Queued 0 digests and 0 messages for 109588
      [PID 13107]     Queued 0 digests and 20 messages for 1199631
      [PID 13107]     Queued 0 digests and 0 messages for 2050058
      [PID 13107]     Queued 0 digests and 3 messages for 843546
      [PID 13107]     Queued 0 digests and 0 messages for 2643385
      [PID 13107]     Queued 0 digests and 0 messages for 1964410
      [PID 13107] ... used 293 dbqueries
      [PID 13107] ... used 2.4785959720612 seconds
      [PID 13107] Scheduled task failed: Forum mailings and maintenance jobs (mod_forum\task\cron_task),Suspended account
      

      Analysis of the problem

      • The reason for this is that the new forum cron code attempts to create adhoc delivery jobs for users who have been inactivated.
      • If such users had subscribed before they were inactivated, they are returned by the method mod_forum\subscriptions\fetch_subscribed_users()
      • Later in the processing chain, we attempt to queue an adhoc task to be run as the given user (making use of the MDL-59084 feature): We call mod_forum\task\cron_task\queue_user_tasks() which in turn calls core\task\manager::queue_adhoc_task()
      • In the core\task\manager::queue_adhoc_task() there is an input check that the adhoc task's user is an active one: core_user::require_active_user() which fails and throws the said exception in two not-covered cases:

                if ($checksuspended and $user->suspended) {
                    throw new moodle_exception('suspended', 'auth');
                }
         
                if ($checknologin and $user->auth == 'nologin') {
                    throw new moodle_exception('suspended', 'auth');
                }
        

      Solution

      We need to make sure that mod_forum\subscriptions\fetch_subscribed_users() does not include users that would be later detected as inactive.

      Steps to reproduce

      1. Apply the submitted patch
      2. Undo the changes of the file mod/forum/classes/subscriptions.php
      3. Run the mod/forum/tests/mail_test.php unit tests

            mudrd8mz David Mudrák (@mudrd8mz)
            mudrd8mz David Mudrák (@mudrd8mz)
            Andrew Lyons Andrew Lyons
            Adrian Greeve Adrian Greeve
            CiBoT CiBoT
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 5 hours, 10 minutes
                5h 10m

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