[sr-dev] git:3.3: modules_k/pua: Adjusted locking for dialog insertion. Candidate fix for "temporary dialog" error reported by Juha

Peter Dunkley peter.dunkley at crocodile-rcs.com
Tue Sep 11 16:46:09 CEST 2012


Module: sip-router
Branch: 3.3
Commit: 91e8cb4bf7456eeebefa96269887f6aae46626d3
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=91e8cb4bf7456eeebefa96269887f6aae46626d3

Author: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley at crocodile-rcs.com>
Date:   Tue Sep 11 13:23:23 2012 +0100

modules_k/pua: Adjusted locking for dialog insertion.  Candidate fix for "temporary dialog" error reported by Juha
(cherry picked from commit b0d642016cca83c519ea9aa0e04aa9bf353e07e4)

---

 modules_k/pua/hash.c           |   18 +++---------------
 modules_k/pua/hash.h           |    3 ++-
 modules_k/pua/pua.c            |    7 ++++++-
 modules_k/pua/send_publish.c   |    4 +++-
 modules_k/pua/send_subscribe.c |    6 ++----
 5 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/modules_k/pua/hash.c b/modules_k/pua/hash.c
index 1fa6149..9ad169b 100644
--- a/modules_k/pua/hash.c
+++ b/modules_k/pua/hash.c
@@ -235,7 +235,7 @@ void update_htable(ua_pres_t* p, time_t desired_expires, int expires,
 	}
 }
 /* insert in front; so when searching the most recent result is returned*/
-void _insert_htable(ua_pres_t* presentity, unsigned int hash_code)
+void insert_htable(ua_pres_t* presentity, unsigned int hash_code)
 {
 	ua_pres_t* p= NULL;
 
@@ -253,18 +253,6 @@ void _insert_htable(ua_pres_t* presentity, unsigned int hash_code)
 	p->next= presentity;
 }
 
-void insert_htable(ua_pres_t* presentity)
-{
-	unsigned int hash_code;
-
-	hash_code= core_hash(presentity->pres_uri,presentity->watcher_uri, HASH_SIZE);
-	lock_get(&HashT->p_records[hash_code].lock);
-
-	_insert_htable(presentity, hash_code);
-
-	lock_release(&HashT->p_records[hash_code].lock);
-}
-
 /* This function used to perform a search to find the hash table
    entry that matches the presentity it is passed.  However,
    everywhere it is used it is passed a pointer to the correct
@@ -349,7 +337,7 @@ int convert_temporary_dialog(ua_pres_t *dialog)
 	else
 		return -1;
 
-	_insert_htable(dialog, hash_code);
+	insert_htable(dialog, hash_code);
 
 	lock_release(&HashT->p_records[hash_code].lock);
 
@@ -695,4 +683,4 @@ list_entry_t *get_subs_list(str *did)
 	}
 done:
 	return list;
-}
\ No newline at end of file
+}
diff --git a/modules_k/pua/hash.h b/modules_k/pua/hash.h
index 61ccd54..9912eba 100644
--- a/modules_k/pua/hash.h
+++ b/modules_k/pua/hash.h
@@ -116,7 +116,8 @@ htable_t* new_htable(void);
 
 ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code);
 
-void insert_htable(ua_pres_t* presentity );
+void insert_htable(ua_pres_t* presentity, unsigned int hash_code);
+
 
 void update_htable(ua_pres_t* presentity,time_t desired_expires,
 		int expires, str* etag, unsigned int hash_code, str* contact);
diff --git a/modules_k/pua/pua.c b/modules_k/pua/pua.c
index 2297219..8734d35 100644
--- a/modules_k/pua/pua.c
+++ b/modules_k/pua/pua.c
@@ -391,6 +391,7 @@ static int db_restore(void)
 	int watcher_col,callid_col,totag_col,fromtag_col,cseq_col,remote_contact_col;
 	int event_col,contact_col,tuple_col,record_route_col, extra_headers_col;
 	int version_col;
+	unsigned int hash_code;
 
 	if (dbmode==PUA_DB_ONLY)
 	{
@@ -643,7 +644,11 @@ static int db_restore(void)
 			}
 
 			print_ua_pres(p);
-			insert_htable(p);
+
+			hash_code= core_hash(p->pres_uri, p->watcher_uri, HASH_SIZE);
+			lock_get(&HashT->p_records[hash_code].lock);
+			insert_htable(p, hash_code);
+			lock_release(&HashT->p_records[hash_code].lock);
 		}
 
 	} while((db_fetch_next(&pua_dbf, pua_fetch_rows, pua_db, &res)==1)
diff --git a/modules_k/pua/send_publish.c b/modules_k/pua/send_publish.c
index 97935c1..4273495 100644
--- a/modules_k/pua/send_publish.c
+++ b/modules_k/pua/send_publish.c
@@ -422,7 +422,9 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
 	}
 	else
  	{
-		insert_htable(presentity);
+		lock_get(&HashT->p_records[hash_code].lock);
+		insert_htable(presentity, hash_code);
+		lock_release(&HashT->p_records[hash_code].lock);
 	}
 	LM_DBG("***Inserted in hash table\n");
 
diff --git a/modules_k/pua/send_subscribe.c b/modules_k/pua/send_subscribe.c
index 89a8141..c1476cd 100644
--- a/modules_k/pua/send_subscribe.c
+++ b/modules_k/pua/send_subscribe.c
@@ -1011,9 +1011,6 @@ int send_subscribe(subs_info_t* subs)
 		int size;
 insert:
 	
-		if (dbmode!=PUA_DB_ONLY)
-			lock_release(&HashT->p_records[hash_code].lock);
-
 		if (subs->expires == 0)
 			/* Don't create a new dialog when expires == 0 */
 			goto done;	
@@ -1123,7 +1120,8 @@ insert:
 		}
 		else
 		{
-			insert_htable(presentity);
+			insert_htable(presentity, hash_code);
+			lock_release(&HashT->p_records[hash_code].lock);
 		}
 
 		uac_r.dialog->rem_target.s = 0;




More information about the sr-dev mailing list