<p>Hi,</p>

<p>I'm using t_reply if onreply_route as follow:</p>

<pre><code>route {
  ...
  t_on_reply("ERROR");
  ...
  t_relay();
}

onreply_route[ERROR] {
  t_reply("500", "Error");
}
</code></pre>

<p>I have this call flow:</p>

<pre><code>CLIENT         KAMAILIO         CARRIER
|--- INVITE --->  |
                  |---- INVITE --->|
                  |<---- 100 ------|
|<--- 100 --------|
                  |<---- 503 ------|
                  |---- ACK ------>|
|<--- 500 --------|
|---- ACK ------->|
                  |---- CANCEL --->|
                  |<--- 487 -------|
</code></pre>

<p>Kamailio sends a CANCEL message to a branch terminated by the carrier.</p>

<p>I'm not sure it is the good way to fix this issue (espacially in use cases involving multiple branches) but here is a patch that work for me on current master:</p>

<pre><code>diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c
index b2e6e53..4b9e142 100644
--- a/modules/tm/t_reply.c
+++ b/modules/tm/t_reply.c
@@ -571,7 +571,7 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len,
                        }
                }
                cleanup_uac_timers( trans );
-               if (is_invite(trans)){
+               if (is_invite(trans  && get_route_type() != TM_ONREPLY_ROUTE)){
                        prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0);
 #ifdef CANCEL_REASON_SUPPORT
                        cancel_data.reason.cause=code;
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/kamailio/kamailio/issues/315">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZeOW5Id8ve_fp2pMEWewIqZGdPDuks5ovXVOgaJpZM4F47oG.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/315"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>