[JDEV] [patch users.c]
Rodolphe Duge de Bernonville
rod at idealx.com
Tue Feb 20 04:22:23 CST 2001
With asynchronous IO and heavy load, problems
may occure in jsm/users.c.
- js__usercount may be wrong.
- If the xdb_get call to retrieve user name and password is too
long, you can have many calls to ghash_put for the same
user. This will corrupt the udata field in the session struct.
So you must test after the xdb_get call if the user
is already in the cache.
+ finally : this cache and the reference counter was the source of
many problems (see a precedent mail of david, dlecorfec at idealx.com,
he has had to increase this counter in jsm/modules.c in js_mapi_call
). And I have seen that if a session was too long to open (ie when
a _js_session_start is in a mtq), it may happen that the udata
struct was deleted ... so I have put a
s->u->ref++; in js_session_new
and a
s->u->ref--; in _js_session_start
and finally to avoid that, I have decided that for a user with a session
the entry in this cache is permanent until he leave ...
so just put a
s->u->ref--; in _js_session_end
@@ -57,7 +57,12 @@
* is positive, or if there are active sessions
* we can't free it, so return immediately
*/
- if(u->ref > 0 || (u->sessions != NULL && ++js__usercount))
+ if (u->sessions != NULL){
+ js__usercount++;
+ return 1;
+ }
+
+ if(u->ref > 0)
return 1;
log_debug(ZONE,"freeing %s",u->user);
@@ -114,11 +132,11 @@
udata js_user(jsmi si, jid id, HASHTABLE ht)
{
pool p;
- udata cur, newu;
- char *ustr;
+ udata cur, newu, tmpu = NULL;
+ char *ustr, *u;
xmlnode x;
jid uid;
-
+
if(si == NULL || id == NULL || id->user == NULL) return NULL;
/* get the host hash table if it wasn't provided */
@@ -158,9 +179,14 @@
newu->id = jid_new(p,jid_full(uid));
/* got the user, add it to the user list */
- ghash_put(ht,newu->user,newu);
+ if ((tmpu=ghash_get(ht, u)) == NULL)
+ ghash_put(ht,newu->user,newu);
+ else{
+ pool_free(p);
+ newu = tmpu;
+ }
+
log_debug(ZONE,"js_user debug %X
%X",ghash_get(ht,newu->user),newu);
return newu;
}
-
More information about the JDev
mailing list