Browse code

tm: skip resuming suspended transactions put on wait

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

Daniel-Constantin Mierla authored on 09/10/2019 10:38:14
Showing 3 changed files
... ...
@@ -1568,11 +1568,12 @@ int t_get_canceled_ident(struct sip_msg* msg, unsigned int* hash_index,
1568 1568
  *                0).
1569 1569
  * @param hash_index - searched transaction hash_index (part of the ident).
1570 1570
  * @param label - searched transaction label (part of the ident).
1571
+ * @param filter - if 1, skip transaction put on-wait (terminated state).
1571 1572
  * @return -1 on error/not found, 1 on success (found)
1572 1573
  * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED).
1573 1574
  */
1574
-int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
1575
-		unsigned int label)
1575
+int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index,
1576
+		unsigned int label, int filter)
1576 1577
 {
1577 1578
 	struct cell* p_cell;
1578 1579
 	struct entry* hash_bucket;
... ...
@@ -1590,9 +1591,19 @@ int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
1590 1590
 #endif
1591 1591
 	hash_bucket=&(get_tm_table()->entries[hash_index]);
1592 1592
 	/* all the transactions from the entry are compared */
1593
-	clist_foreach(hash_bucket, p_cell, next_c){
1593
+	clist_foreach(hash_bucket, p_cell, next_c) {
1594 1594
 		prefetch_loc_r(p_cell->next_c, 1);
1595
-		if(p_cell->label == label){
1595
+		if(p_cell->label == label) {
1596
+			if(filter==1) {
1597
+				if(t_on_wait(p_cell)) {
1598
+					/* transaction in terminated state */
1599
+					UNLOCK_HASH(hash_index);
1600
+					set_t(0, T_BR_UNDEFINED);
1601
+					*trans=NULL;
1602
+					LM_DBG("transaction in terminated phase - skipping\n");
1603
+					return -1;
1604
+				}
1605
+			}
1596 1606
 			REF_UNSAFE(p_cell);
1597 1607
 			UNLOCK_HASH(hash_index);
1598 1608
 			set_t(p_cell, T_BR_UNDEFINED);
... ...
@@ -1604,14 +1615,27 @@ int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
1604 1604
 
1605 1605
 	UNLOCK_HASH(hash_index);
1606 1606
 	set_t(0, T_BR_UNDEFINED);
1607
-	*trans=p_cell;
1607
+	*trans=NULL;
1608 1608
 
1609 1609
 	LM_DBG("transaction not found\n");
1610 1610
 
1611 1611
 	return -1;
1612 1612
 }
1613 1613
 
1614
-
1614
+/** lookup a transaction based on its identifier (hash_index:label).
1615
+ * @param trans - double pointer to cell structure, that will be filled
1616
+ *                with the result (a pointer to an existing transaction or
1617
+ *                0).
1618
+ * @param hash_index - searched transaction hash_index (part of the ident).
1619
+ * @param label - searched transaction label (part of the ident).
1620
+ * @return -1 on error/not found, 1 on success (found)
1621
+ * Side-effects: sets T and T_branch (T_branch always to T_BR_UNDEFINED).
1622
+ */
1623
+int t_lookup_ident(struct cell ** trans, unsigned int hash_index,
1624
+		unsigned int label)
1625
+{
1626
+	return t_lookup_ident_filter(trans, hash_index, label, 0);
1627
+}
1615 1628
 
1616 1629
 /** check if a transaction is local or not.
1617 1630
  * Check if the transaction corresponding to the current message
... ...
@@ -92,6 +92,8 @@ typedef int (*tset_fr_f)(struct sip_msg*, unsigned int, unsigned int);
92 92
 int t_is_local(struct sip_msg*);
93 93
 int t_get_trans_ident(struct sip_msg* p_msg, unsigned int* hash_index, unsigned int* label);
94 94
 int t_lookup_ident(struct cell** trans, unsigned int hash_index, unsigned int label);
95
+int t_lookup_ident_filter(struct cell ** trans, unsigned int hash_index,
96
+		unsigned int label, int filter);
95 97
 /* lookup a transaction by callid and cseq */
96 98
 int t_lookup_callid(struct cell** trans, str callid, str cseq);
97 99
 
... ...
@@ -187,9 +187,9 @@ int t_continue_helper(unsigned int hash_index, unsigned int label,
187 187
 	backup_T = get_t();
188 188
 	backup_T_branch = get_t_branch();
189 189
 
190
-	if (t_lookup_ident(&t, hash_index, label) < 0) {
190
+	if (t_lookup_ident_filter(&t, hash_index, label, 1) < 0) {
191 191
 		set_t(backup_T, backup_T_branch);
192
-		LM_ERR("transaction not found\n");
192
+		LM_ERR("active transaction not found\n");
193 193
 		return -1;
194 194
 	}
195 195