| 1 |
From e5afdb60d7937e586318dfb22d325897b239e6b1 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Nanang Izzuddin <[email protected]> |
| 3 |
Date: Wed, 6 May 2026 11:33:24 +0700 |
| 4 |
Subject: [PATCH] Add PJSIP_INV_ABSORB_RETRANS_AFTER_ACK macro to opt out of |
| 5 |
#4765 (#4965) |
| 6 |
MIME-Version: 1.0 |
| 7 |
Content-Type: text/plain; charset=UTF-8 |
| 8 |
Content-Transfer-Encoding: 8bit |
| 9 |
|
| 10 |
* Add PJSIP_INV_ABSORB_RETRANS_AFTER_ACK macro to opt out of #4765 behavior |
| 11 |
|
| 12 |
PR #4765 changed the UAS INVITE transaction to delay termination by ~64*T1 |
| 13 |
after ACK so that retransmitted INVITEs are absorbed instead of being |
| 14 |
treated as new requests. This commit adds a compile-time macro |
| 15 |
PJSIP_INV_ABSORB_RETRANS_AFTER_ACK (default 1) to revert to the legacy |
| 16 |
behavior — immediate transaction termination after ACK — for applications |
| 17 |
that depend on the previous timing. |
| 18 |
|
| 19 |
The same-branch-different-CSeq 400 Bad Request handling remains |
| 20 |
unconditional and is not affected by this macro. |
| 21 |
|
| 22 |
* docs: clarify PJSIP_INV_ABSORB_RETRANS_AFTER_ACK behavior |
| 23 |
|
| 24 |
Address review feedback: retransmitted INVITEs are answered by the cached |
| 25 |
2xx retransmission (not silently dropped), and the absorb window is |
| 26 |
configurable via pjsip_cfg()->tsx.td (default ~32 s) rather than a fixed |
| 27 |
64*T1. |
| 28 |
--- |
| 29 |
pjsip/include/pjsip/sip_config.h | 20 +++++++++++++++++++- |
| 30 |
pjsip/src/pjsip-ua/sip_inv.c | 5 +++++ |
| 31 |
pjsip/src/pjsip/sip_transaction.c | 9 ++++++--- |
| 32 |
3 files changed, 30 insertions(+), 4 deletions(-) |
| 33 |
|
| 34 |
diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h |
| 35 |
index 1622648cab..73cc85a640 100644 |
| 36 |
--- a/pjsip/include/pjsip/sip_config.h |
| 37 |
+++ b/pjsip/include/pjsip/sip_config.h |
| 38 |
@@ -1560,7 +1560,7 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) |
| 39 |
# define PJSIP_INV_ACCEPT_UNKNOWN_BODY PJ_FALSE |
| 40 |
#endif |
| 41 |
|
| 42 |
-/** |
| 43 |
+/** |
| 44 |
* Specify whether to check if UPDATE sent in EARLY state has already |
| 45 |
* completed SDP negotiation using reliable provisional responses, as |
| 46 |
* specified in RFC3311 section 5.1. |
| 47 |
@@ -1574,6 +1574,24 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void) |
| 48 |
# define PJSIP_INV_UPDATE_EARLY_CHECK_RELIABLE 0 |
| 49 |
#endif |
| 50 |
|
| 51 |
+/** |
| 52 |
+ * Specify whether to absorb INVITE request retransmissions arriving after |
| 53 |
+ * an ACK has been received for a 2xx response. When enabled (default), the |
| 54 |
+ * INVITE transaction termination is delayed for about ~32 seconds |
| 55 |
+ * (configurable via pjsip_cfg()->tsx.td) so retransmitted INVITEs are |
| 56 |
+ * matched to the existing transaction and answered by the cached 2xx |
| 57 |
+ * retransmission, rather than being treated as new requests. |
| 58 |
+ * |
| 59 |
+ * Set this to 0 to revert to the legacy behavior, where the INVITE |
| 60 |
+ * transaction is terminated immediately after ACK and any subsequent |
| 61 |
+ * retransmission is treated as a new request. See also \pr{4765}. |
| 62 |
+ * |
| 63 |
+ * Default: 1 (enabled) |
| 64 |
+ */ |
| 65 |
+#ifndef PJSIP_INV_ABSORB_RETRANS_AFTER_ACK |
| 66 |
+# define PJSIP_INV_ABSORB_RETRANS_AFTER_ACK 1 |
| 67 |
+#endif |
| 68 |
+ |
| 69 |
/** |
| 70 |
* Specify whether message info will include additional details such as |
| 71 |
* Call-ID and To header information in the log output. When enabled, |
| 72 |
diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c |
| 73 |
index a373b8f470..1fd202d398 100644 |
| 74 |
--- a/pjsip/src/pjsip-ua/sip_inv.c |
| 75 |
+++ b/pjsip/src/pjsip-ua/sip_inv.c |
| 76 |
@@ -763,6 +763,7 @@ static pj_bool_t mod_inv_on_rx_request(pjsip_rx_data *rdata) |
| 77 |
|
| 78 |
/* Now we can terminate the INVITE transaction */ |
| 79 |
if (inv->invite_tsx->status_code/100 == 2) { |
| 80 |
+#if PJSIP_INV_ABSORB_RETRANS_AFTER_ACK |
| 81 |
/* Stop retransmissions of 200 response */ |
| 82 |
pjsip_tsx_stop_retransmit(inv->invite_tsx); |
| 83 |
|
| 84 |
@@ -774,6 +775,10 @@ static pj_bool_t mod_inv_on_rx_request(pjsip_rx_data *rdata) |
| 85 |
inv->invite_tsx->status_code, |
| 86 |
NULL, |
| 87 |
pjsip_cfg()->tsx.td); |
| 88 |
+#else |
| 89 |
+ pjsip_tsx_terminate(inv->invite_tsx, |
| 90 |
+ inv->invite_tsx->status_code); |
| 91 |
+#endif |
| 92 |
} else { |
| 93 |
/* If the response was not 2xx, the ACK is considered part of |
| 94 |
* the INVITE transaction, so should have been handled by |
| 95 |
diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c |
| 96 |
index f16fc7266b..0f1c96bbf0 100644 |
| 97 |
--- a/pjsip/src/pjsip/sip_transaction.c |
| 98 |
+++ b/pjsip/src/pjsip/sip_transaction.c |
| 99 |
@@ -3718,19 +3718,22 @@ static pj_status_t tsx_on_state_completed_uas( pjsip_transaction *tsx, |
| 100 |
tsx_cancel_timer( tsx, &tsx->timeout_timer ); |
| 101 |
|
| 102 |
/* Schedule tsx termination */ |
| 103 |
+#if PJSIP_INV_ABSORB_RETRANS_AFTER_ACK |
| 104 |
if (tsx->status_code/100 == 2) { |
| 105 |
/* Normally 2xx response is handled by TU (not considered |
| 106 |
* part of the INVITE tsx), anyway if it comes here, let's |
| 107 |
* delay the tsx termination to absorb INVITE retransmission |
| 108 |
* for about 64*T1 (~32 seconds). See also #4765. |
| 109 |
*/ |
| 110 |
- timeout = td_timer_val; |
| 111 |
- } else { |
| 112 |
+ timeout = td_timer_val; |
| 113 |
+ } else |
| 114 |
+#endif |
| 115 |
+ { |
| 116 |
/* Timer I is T4 timer for unreliable transports, and |
| 117 |
* zero seconds for reliable transports. |
| 118 |
*/ |
| 119 |
if (tsx->is_reliable) { |
| 120 |
- timeout.sec = 0; |
| 121 |
+ timeout.sec = 0; |
| 122 |
timeout.msec = 0; |
| 123 |
} else { |
| 124 |
timeout.sec = t4_timer_val.sec; |