o365-moodle
o365-moodle copied to clipboard
Scheduled task failed: Sync users with Azure AD. (local_o365\task\usersync) Error reading from database
We're having an issue where a number of our Azure users are missing from Moodle. Having checked the sync task, it is producing the below error on a full sync so never syncs all the users.
Moodle 3.114 / Microsoft 365 plugin 3.11.1 2021051705
Execute scheduled task: Sync users with Azure AD. (local_o365\task\usersync) ... started 15:13:39. Current memory use 12.1MB. ...... Starting sync ...... No skiptoken (delta) stored. ...... No deltatoken stored. ...... Using delta sync. ...... Contacting Azure AD... ...... Got response from Azure AD ...... Storing deltatoken ...... Clearing skiptoken (delta) (none received) ...... 11047 users received. Syncing... ...... 10000 users in chunk. Syncing... ... used 7 dbqueries ... used 1218.516176939 seconds Scheduled task failed: Sync users with Azure AD. (local_o365\task\usersync),Error reading from database
Hi @flipmode45,
Please turn debug on and paste full error details.
Regards, Lai
Execute scheduled task: Sync users with Azure AD. (local_o365\task\usersync) ... started 08:30:00. Current memory use 12.1MB. ...... Starting sync ...... No skiptoken (delta) stored. ...... No deltatoken stored. ...... Using delta sync. ...... Contacting Azure AD... ...... Got response from Azure AD ...... Storing deltatoken ...... Clearing skiptoken (delta) (none received) ...... 11036 users received. Syncing... ...... 10000 users in chunk. Syncing... ++ Did you remember to make the first column something unique in your call to get_records? Duplicate value 'external_examiner' found in column 'username'. ++
- line 985 of \lib\dml\sqlsrv_native_moodle_database.php: call to debugging()
- line 936 of \local\o365\classes\feature\usersync\main.php: call to sqlsrv_native_moodle_database->get_records_sql()
- line 253 of \local\o365\classes\task\usersync.php: call to local_o365\feature\usersync\main->sync_users()
- line 186 of \local\o365\classes\task\usersync.php: call to local_o365\task\usersync->sync_users()
- line 253 of \lib\cronlib.php: call to local_o365\task\usersync->execute()
- line 167 of \admin\cli\scheduled_task.php: call to cron_run_inner_scheduled_task() ... used 10 dbqueries
Notice: fwrite(): write of 22 bytes failed with errno=22 Invalid argument in D:\moodlesite\lib\moodlelib.php on line 9136
@weilai-irl Any ideas with this please?
Hi @flipmode45,
It looks like you have duplicate Moodle users with same username "external_examiner", possibly with different mnethostid. Could you check your list of users to confirm? If confirmed, could you verify these users are valid? The plugins assume Moodle usernames are unique, (i.e. it hasn't been specifically tested for Moodle sites having multiple MNet hosts). If supporting multiple mnethostid is required, please log a feature request and it will be queued.
Regards, Lai
Hi @weilai-irl That error around a duplicate user seems like a misnomer. I've been into the database and removed the duplicate user record, but the task still ends with the same error each time:
Notice: fwrite(): write of 21 bytes failed with errno=22 Invalid argument in D:\moodlesite\lib\moodlelib.php on line 9136
The full output is now:
Execute scheduled task: Sync users with Azure AD. (local_o365\task\usersync) ... started 09:03:04. Current memory use 12.1MB. ...... Starting sync ...... No skiptoken (delta) stored. ...... No deltatoken stored. ...... Using delta sync. ...... Contacting Azure AD... ...... Got response from Azure AD ...... Storing deltatoken ...... Clearing skiptoken (delta) (none received) ...... 11129 users received. Syncing... ...... 10000 users in chunk. Syncing... ... used 7 dbqueries
Notice: fwrite(): write of 21 bytes failed with errno=22 Invalid argument in D:\moodlesite\lib\moodlelib.php on line 9136
Hi @flipmode45,
I don't think this issue is caused by the Microsoft plugins. The plugins make calls to function mtrace() in lib/moodlelib.php to print debugging information, and it's the call to mtrace() that throws this error. I can confirm that there is no complicated logic in the calls to mtrace() function from the plugins.
You will need to troubleshoot this on your end as the issue is most likely related to your environment. Maybe write a simple script to do nothing but making a call to the mtrace() function, and see if it works. By looking at the implementation of mtrace(), the most probable reason of the issue is with STDOUT. Maybe it's not writable?
Regards, Lai
Hi all, this might not be the same issue, but I think it is worth you trying what is mentioned here on my blog. It's happened to a few of our larger customers when they run a full sync or when it hits a Error in delta usersync: Error in API call. (I'm suspecting caused by a duplicate email) then the sync does not use the deltatoken.
I imagine the value of your max_allowed_packet will be set to the default value of 16mb, set this to 256mb and the sync will complete without the database going away.
Regards, Ray.