[Building Sakai] theory about missing users in site

Charles Hedrick hedrick at rutgers.edu
Wed Mar 5 08:10:41 PST 2014


I have a site that any user can join. It’s used for training people, and documenting that they have been trained.

They use a JSP that joins them to the site and then puts them into it. They take a test in the site. but 15 min into the test, they are suddenly no longer in the site.

Here’s my theory:

The code in the JSP was

+ 	         AuthzGroup realmEdit = AuthzGroupService.getAuthzGroup(realmId);
+ 	         realmEdit.addMember(email, role, true, false);
+ 	         AuthzGroupService.save(realmEdit);

But I think this code has a race condition. I believe getAuthzGroup will get a cached version of the realm. So it could be out of date. If a user is added on one front end, the next user could fetch an old version of the realm, add to that, and save it, thus losing the first user. The next time the first front end refreshes its cache, the user will be out of the site.

What I’m trying as a fix is to use joinGroup. This appears to be race-free, because it uses SQL that does an add.

In my case it has a problem, in that joinGroup always works on the current user. I want to do this before the login. I can fake it, but it would be convenient to have addUser and removeUser operations that specify a user.

The situation would be better if there were a getAuthzGroupEdit, that always fetched from the database. That would limit the race condition to a fairly small window.

Another approach would be for the AuthzGroup object to have a duplicate copy of all the fields.The save operation does’t wipe out the group and recreate it. It quite intelligently compares current and new value ,and make the appropriate changes. But you really want to compare with the original value of the object, not the current database.

Consider

getAuthGroup returns {Smith{
someone on another front end adds Jones
the program adds White
the program saves {Smith, White}

You want to compare the new value, {Smith, White} against the original value when the group was fetched, i.e. {Smith}. That will cause you to add White. The code compares it with the current database, which is {Smith, Jones}, thus causing it to delete Jones and add White.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20140305/ae8c44de/attachment.html 


More information about the sakai-dev mailing list