Переглянути джерело

tm: skip resuming suspended transactions put on wait

- transaction is expired in that moment, pending its destroy process
- GH #2055
Daniel-Constantin Mierla 6 роки тому
батько
коміт
52afc7b70f
3 змінених файлів з 34 додано та 8 видалено
  1. 30 6
      src/modules/tm/t_lookup.c
  2. 2 0
      src/modules/tm/t_lookup.h
  3. 2 2
      src/modules/tm/t_suspend.c

+ 30 - 6
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

+ 2 - 0
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);
 

+ 2 - 2
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;
 	}