[sr-dev] git:5.3:c44bd17c: tm: skip resuming suspended transactions put on wait

Daniel-Constantin Mierla miconda at gmail.com
Wed Oct 9 18:51:54 CEST 2019


Module: kamailio
Branch: 5.3
Commit: c44bd17c79bc0119ae201b826d84b9514700eda9
URL: https://github.com/kamailio/kamailio/commit/c44bd17c79bc0119ae201b826d84b9514700eda9

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-10-09T18:48:40+02:00

tm: skip resuming suspended transactions put on wait

- transaction is expired in that moment, pending its destroy process
- GH #2055

(cherry picked from commit 52afc7b70f8e4abfb347c84872ab7daa202a6a24)

---

Modified: src/modules/tm/t_lookup.c
Modified: src/modules/tm/t_lookup.h
Modified: src/modules/tm/t_suspend.c

---

Diff:  https://github.com/kamailio/kamailio/commit/c44bd17c79bc0119ae201b826d84b9514700eda9.diff
Patch: https://github.com/kamailio/kamailio/commit/c44bd17c79bc0119ae201b826d84b9514700eda9.patch

---

diff --git a/src/modules/tm/t_lookup.c b/src/modules/tm/t_lookup.c
index b1182a9e71..510599f742 100644
--- a/src/modules/tm/t_lookup.c
+++ b/src/modules/tm/t_lookup.c
@@ -1568,11 +1568,12 @@ int t_get_canceled_ident(struct sip_msg* msg, unsigned int* hash_index,
  *                0).
  * @param hash_index - searched transaction hash_index (part of the ident).
  * @param label - searched transaction label (part of the ident).
+ * @param filter - if 1, skip transaction put on-wait (terminated state).
  * @return -1 on error/not found, 1 on success (found)
  * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED).
  */
-int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
-		unsigned int label)
+int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index,
+		unsigned int label, int filter)
 {
 	struct cell* p_cell;
 	struct entry* hash_bucket;
@@ -1590,9 +1591,19 @@ int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
 #endif
 	hash_bucket=&(get_tm_table()->entries[hash_index]);
 	/* all the transactions from the entry are compared */
-	clist_foreach(hash_bucket, p_cell, next_c){
+	clist_foreach(hash_bucket, p_cell, next_c) {
 		prefetch_loc_r(p_cell->next_c, 1);
-		if(p_cell->label == label){
+		if(p_cell->label == label) {
+			if(filter==1) {
+				if(t_on_wait(p_cell)) {
+					/* transaction in terminated state */
+					UNLOCK_HASH(hash_index);
+					set_t(0, T_BR_UNDEFINED);
+					*trans=NULL;
+					LM_DBG("transaction in terminated phase - skipping\n");
+					return -1;
+				}
+			}
 			REF_UNSAFE(p_cell);
 			UNLOCK_HASH(hash_index);
 			set_t(p_cell, T_BR_UNDEFINED);
@@ -1604,14 +1615,27 @@ int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
 
 	UNLOCK_HASH(hash_index);
 	set_t(0, T_BR_UNDEFINED);
-	*trans=p_cell;
+	*trans=NULL;
 
 	LM_DBG("transaction not found\n");
 
 	return -1;
 }
 
-
+/** lookup a transaction based on its identifier (hash_index:label).
+ * @param trans - double pointer to cell structure, that will be filled
+ *                with the result (a pointer to an existing transaction or
+ *                0).
+ * @param hash_index - searched transaction hash_index (part of the ident).
+ * @param label - searched transaction label (part of the ident).
+ * @return -1 on error/not found, 1 on success (found)
+ * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED).
+ */
+int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
+		unsigned int label)
+{
+	return t_lookup_ident_filter(trans, hash_index, label, 0);
+}
 
 /** check if a transaction is local or not.
  * Check if the transaction corresponding to the current message
diff --git a/src/modules/tm/t_lookup.h b/src/modules/tm/t_lookup.h
index 347d088d48..2a5e67d3de 100644
--- a/src/modules/tm/t_lookup.h
+++ b/src/modules/tm/t_lookup.h
@@ -92,6 +92,8 @@ typedef int (*tset_fr_f)(struct sip_msg*, unsigned int, unsigned int);
 int t_is_local(struct sip_msg*);
 int t_get_trans_ident(struct sip_msg* p_msg, unsigned int* hash_index, unsigned int* label);
 int t_lookup_ident(struct cell** trans, unsigned int hash_index, unsigned int label);
+int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index,
+		unsigned int label, int filter);
 /* lookup a transaction by callid and cseq */
 int t_lookup_callid(struct cell** trans, str callid, str cseq);
 
diff --git a/src/modules/tm/t_suspend.c b/src/modules/tm/t_suspend.c
index be7b0a6842..949340f1ce 100644
--- a/src/modules/tm/t_suspend.c
+++ b/src/modules/tm/t_suspend.c
@@ -187,9 +187,9 @@ int t_continue_helper(unsigned int hash_index, unsigned int label,
 	backup_T = get_t();
 	backup_T_branch = get_t_branch();
 
-	if (t_lookup_ident(&t, hash_index, label) < 0) {
+	if (t_lookup_ident_filter(&t, hash_index, label, 1) < 0) {
 		set_t(backup_T, backup_T_branch);
-		LM_ERR("transaction not found\n");
+		LM_ERR("active transaction not found\n");
 		return -1;
 	}
 




More information about the sr-dev mailing list