Moodle 2.8 ldap AD CLI sync error

Moodle 2.8 ldap AD CLI sync error

by Dolton Dilon -
Number of replies: 9
Hi folks,
I seem to be having some sync issues with Moodle both 2.7.3 and 2.8.1. Our installation is clustered LAMP CentOS 6.6 and AD env.  We are trying to sync 30,000 ldap entries. After entry ~5,000 or so it tossed the following error. IDs and names are unique and our 2.6.4 instance seems fine.

 Potential coding error - active database transaction detected during request shutdown:
* line 935 of /auth/ldap/auth.php: call to moodle_database->start_delegated_transaction()
* line 63 of /auth/ldap/cli/sync_users.php: call to auth_plugin_ldap->sync_users()


Any ideas or suggestions?

Average of ratings: -
In reply to Dolton Dilon

Re: Moodle 2.8 ldap AD CLI sync error

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Dolton,
is that related with the time spent on the CLI sync? Otherwise, it could be an uncaught exception and you could check it by modifying a bit the code:

$ git diff auth/ldap/
diff --git a/auth/ldap/cli/sync_users.php b/auth/ldap/cli/sync_users.php
index 6898293a..257b21e 100644
--- a/auth/ldap/cli/sync_users.php
+++ b/auth/ldap/cli/sync_users.php
@@ -60,5 +60,9 @@ if (!is_enabled_auth('ldap')) {
 }

 $ldapauth = get_auth_plugin('ldap');
-$ldapauth->sync_users(true);
+try {
+    $ldapauth->sync_users(true);
+} catch (Exception $ex) {
+    debugging('[AUTH LDAP]: '.$ex->getMessage(), DEBUG_DEVELOPER, $ex->getTrace());
+}

The possible exception should explain something about the reason why your users sync stops working around that size/time.

You're not alone: https://moodle.org/mod/forum/discuss.php?d=275394.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Moodle 2.8 ldap AD CLI sync error

by Dolton Dilon -

Thanks Matteo. I will give that a go and let you know. I am not sure if it is related to the time or number of entries synced but everything is fine for smaller OUs (~1000 or so).

In reply to Dolton Dilon

Re: Moodle 2.8 ldap AD CLI sync error

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

OK, will wait for your post.
Based on your feedback, I could raise an improvement to add that try/catch block on the main stream, if that will highlight the real issue behind your scenes.

It could be something similar to what suggested above, keeping care of nicely rollback the DB transaction too:

$ git diff auth/ldap/
diff --git a/auth/ldap/cli/sync_users.php b/auth/ldap/cli/sync_users.php
index 6898293a..388178b 100644
--- a/auth/ldap/cli/sync_users.php
+++ b/auth/ldap/cli/sync_users.php
@@ -60,5 +60,12 @@ if (!is_enabled_auth('ldap')) {
 }

 $ldapauth = get_auth_plugin('ldap');
-$ldapauth->sync_users(true);
+try {
+    $ldapauth->sync_users(true);
+} catch (Exception $ex) {
+    debugging('[AUTH LDAP]: '.$ex->getMessage(), DEBUG_DEVELOPER, $ex->getTrace());
+    if ($DB->is_transaction_started()) {
+        $DB->force_transaction_rollback();
+    }
+}

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Moodle 2.8 ldap AD CLI sync error

by Jonathan Moore -

I am seeing the same error. After applying your suggested changes and enabling debugging, it appears to be an out of memory error for my server. I see the following error output.


PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /opt/rh/httpd24/root/var/www/ldaptest/cache/classes/loaders.php on line 544


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /opt/rh/httpd24/root/var/www/ldaptest/cache/classes/loaders.php on line 544

Potential coding error - active database transaction detected during request shutdown:

* line 935 of /auth/ldap/auth.php: call to moodle_database->start_delegated_transaction()

* line 64 of /auth/ldap/cli/sync_users.php: call to auth_plugin_ldap->sync_users()


I am going to try increasing the allocation to see if that will resolve the problem.

Average of ratings: Useful (1)
In reply to Jonathan Moore

Re: Moodle 2.8 ldap AD CLI sync error

by Jonathan Moore -

Increasing the memory limit fixed the issue for me.

Average of ratings: Useful (2)
In reply to Jonathan Moore

Re: Moodle 2.8 ldap AD CLI sync error

by Mike Halverson -

Jonathan


I'm having the same issue.  What did you increase your memory limit to and where/how did you increase the memory limit?  Thanks for taking the time to explain this.

In reply to Mike Halverson

Re: Moodle 2.8 ldap AD CLI sync error

by Mike Halverson -

Jonathan


I was able to figure out that I needed to increase my memory from 128 to 256 in the php.ini


Thanks

Average of ratings: Useful (1)
In reply to Mike Halverson

Re: Moodle 2.8 ldap AD CLI sync error

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Hi,

I had a similar problem (on Moodle 2.9) with CAS authentication, launching moodle/auth/cas/cli/sync_users.php, exactly like in this thread.

Problem resolved using more PHP memory (512M to 1024M in my case ; memory_limit=1024M) to execute this script smile

Séverin


Average of ratings: Useful (3)