Skip to content

Commit

Permalink
usrloc: Avoid firing DELETE and EXPIRE for same ct
Browse files Browse the repository at this point in the history
This patch fixes a usrloc callbacks API issue where both the
UL_CONTACT_DELETE and UL_CONTACT_EXPIRE events would often be fired for
the same contact, when the "write-back" SQL mode is in use.

The following modules should notice improved behavior:
    mid_registrar, pua_bla, pua_usrloc, snmpstats

(cherry picked from commit 1a50d66)
  • Loading branch information
liviuchircu committed Apr 9, 2024
1 parent 68bfb9b commit 5f7b250
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 4 additions & 3 deletions modules/usrloc/ucontact.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ void free_ucontact_coords(ucontact_coords coords);
int is_my_ucontact(ucontact_t *c);

/*! \brief
* ancient time used for marking the contacts forced to expired
* Non-zero but still ancient time which forces a contact to expire
*/
#define UL_EXPIRED_TIME 10
#define FORCE_EXPIRED_CONTACT(c) ((c)->expires == UL_EXPIRED_TIME)

/*
* Valid contact is a contact that either didn't expire yet or is permanent
* A contact is valid when it is neither expired nor permanent
*/
#define VALID_CONTACT(c, t) ((c->expires>t) || (c->expires==0))
#define VALID_CONTACT(c, t) ((c)->expires>(t) || (c)->expires==0)


/*! \brief
Expand Down
14 changes: 6 additions & 8 deletions modules/usrloc/urecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ static inline int nodb_timer(urecord_t* _r)

while(ptr) {
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE))
/* for forcibly expired contacts, DELETE event is already run */
if (!FORCE_EXPIRED_CONTACT(ptr) && exists_ulcb_type(UL_CONTACT_EXPIRE))
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL);

LM_DBG("Binding '%.*s','%.*s' has expired\n",
Expand Down Expand Up @@ -282,10 +282,9 @@ static inline int ALLOW_UNUSED wt_timer(urecord_t* _r)

while(ptr) {
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
/* for forcibly expired contacts, DELETE event is already run */
if (!FORCE_EXPIRED_CONTACT(ptr) && exists_ulcb_type(UL_CONTACT_EXPIRE))
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL);
}

LM_DBG("Binding '%.*s','%.*s' has expired\n",
ptr->aor->len, ZSW(ptr->aor->s),
Expand Down Expand Up @@ -325,10 +324,9 @@ static inline int wb_timer(urecord_t* _r,query_list_t **ins_list)

while(ptr) {
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
/* for forcibly expired contacts, DELETE event is already run */
if (!FORCE_EXPIRED_CONTACT(ptr) && exists_ulcb_type(UL_CONTACT_EXPIRE))
run_ul_callbacks( UL_CONTACT_EXPIRE, ptr, NULL);
}

LM_DBG("Binding '%.*s','%.*s' has expired\n",
ptr->aor->len, ZSW(ptr->aor->s),
Expand Down

0 comments on commit 5f7b250

Please sign in to comment.