Skip to content

Commit a6a22c9

Browse files
committed
presence: Fix leaking of activewatchers in database (with clustering)
If you're using clustering, without tags (or with tags, but without fallback2db), you would end up with a lot of active watchers in the database that never got cleaned up. Before 929ab4d: - all stale activewatcher records in the db got purged. After: - if you're not clustering, all stale active watcher got purged; - if you are, only those with the sharing_tag set. However, the sharing tag is not necessarily set: - it is an optional argument to handle_subscribe; - and setting it in handle_subscribe does not write to the database because of missing code in the fallback2db==0 bit; - and even it it were set, then adding the argument to handle_subscribe does not "activate" the sharing tag. (Also interesting to know: a 408 or 481 after the this-subscription-is-expired NOTIFY _would_ cause the individual record to get deleted. But any other response, including 200, would leave the record to get sorted by the periodic purge.) This changeset reverts parts of the aforementioned commit by always purging stale records if the sharing_tag is NULL. Thus restoring behaviour to pre-3.1.0 and pre-2.4.8.
1 parent 430d4c8 commit a6a22c9

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

modules/presence/subscribe.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ static inline int is_shtag_active( str *my_tag, str **active_tags)
13561356
void update_db_subs(db_con_t *db,db_func_t *dbf, shtable_t hash_table,
13571357
int htable_size, int no_lock, handle_expired_func_t handle_expired_func)
13581358
{
1359-
static db_ps_t my_ps_delete = NULL;
1359+
static db_ps_t my_ps_delete = NULL, my_ps_delete_null = NULL;
13601360
static db_ps_t my_ps_update = NULL, my_ps_insert = NULL;
13611361
db_key_t query_cols[22], update_cols[8];
13621362
db_val_t query_vals[22], update_vals[8];
@@ -1664,32 +1664,32 @@ void update_db_subs(db_con_t *db,db_func_t *dbf, shtable_t hash_table,
16641664
lock_release(&hash_table[i].lock);
16651665
}
16661666

1667-
/* now that all records were updated, delete whatever
1667+
/* now that all records were updated, delete whatever
16681668
was still left as expired */
1669-
update_cols[0]= &str_expires_col;
1669+
update_cols[0] = &str_expires_col;
16701670
update_vals[0].type = DB_INT;
16711671
update_vals[0].nul = 0;
16721672
update_vals[0].val.int_val = (int)time(NULL);
16731673
update_ops[0] = OP_LT;
16741674

1675+
update_cols[1] = &str_sharing_tag_col;
1676+
update_vals[1].nul = 1;
1677+
update_ops[1] = OP_IS_NULL;
1678+
16751679
if (dbf->use_table(db, &active_watchers_table) < 0) {
16761680
LM_ERR("deleting expired information from database\n");
16771681
return;
16781682
}
16791683

1680-
if (sh_tags==NULL) {
1681-
1682-
/* no clustering, simply delete all expired subs */
1683-
LM_DBG("delete all expired subscriptions\n");
1684+
/* no clustering, simply delete all expired subs with NULL sh tags */
1685+
LM_DBG("delete all expired subscriptions\n");
16841686

1685-
CON_SET_CURR_PS(db, &my_ps_delete);
1686-
if (dbf->delete(db, update_cols, update_ops, update_vals, 1) < 0)
1687-
LM_ERR("deleting expired information from database\n");
1688-
1689-
} else {
1687+
CON_SET_CURR_PS(db, &my_ps_delete_null);
1688+
if (dbf->delete(db, update_cols, update_ops, update_vals, 2) < 0)
1689+
LM_ERR("deleting expired information from database\n");
16901690

1691+
if (sh_tags != NULL) {
16911692
/* clustering, delete only expired subs with active sh tags */
1692-
update_cols[1]= &str_sharing_tag_col;
16931693
update_vals[1].type = DB_STR;
16941694
update_vals[1].nul = 0;
16951695
update_ops[1] = OP_EQ;
@@ -1698,8 +1698,8 @@ void update_db_subs(db_con_t *db,db_func_t *dbf, shtable_t hash_table,
16981698
while(sh_tags[i]) {
16991699
LM_DBG("delete expired subscriptions for tag <%.*s>\n",
17001700
sh_tags[i]->len, sh_tags[i]->s);
1701-
17021701
update_vals[1].val.str_val = *sh_tags[i];
1702+
17031703
CON_SET_CURR_PS(db, &my_ps_delete);
17041704
if (dbf->delete(db, update_cols, update_ops, update_vals, 2) < 0)
17051705
LM_ERR("deleting expired information from database\n");

0 commit comments

Comments
 (0)