<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <tt>Hi Artem,<br>
      <br>
      On the "real-behavior" - OpenSIPS generates and sends an OPTIONS
      request (a NAT ping) via the stale connection to A. You say :<br>
      <br>
      1) the TCP write operation in OpenSIPS  blocks ? (you mentioned
      the tcp_send_timeout)<br>
      <br>
      2) the retransmission you mentioned, are at TCP level or SIP level
      ? If at TCP level, these are done by the TCP/IP stack in the
      Operating System, they are not done by OpenSIPS.<br>
      <br>
      The received BYE is not sent out as the outgoing connection (to A)
      is locked by the process trying to send the OPTIONS to A (assuming
      that the write operation blocks).<br>
      <br>
      Best regards,<br>
    </tt>
    <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu

OpenSIPS Founder and Developer
  <a class="moz-txt-link-freetext" href="https://www.opensips-solutions.com">https://www.opensips-solutions.com</a>
OpenSIPS Summit 2019
  <a class="moz-txt-link-freetext" href="https://www.opensips.org/events/Summit-2019Amsterdam/">https://www.opensips.org/events/Summit-2019Amsterdam/</a>
</pre>
    <div class="moz-cite-prefix">On 03/25/2019 04:40 PM, Artem Chalkov
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:1015401553524846@sas1-19a94364928d.qloud-c.yandex.net">
      <div xmlns="http://www.w3.org/1999/xhtml">Hi all.</div>
      <div xmlns="http://www.w3.org/1999/xhtml">
        <div>Today i encountered some strange behavior in TCP handling.
          Case:</div>
        <div>A - caller, proto=tcp, behind NAT</div>
        <div>B - callee, proto=udp, not behind NAT</div>
        <div>Nathelper is active, so A is pinged by OPTIONS from
          opensips.</div>
        <div>A registering and then calling to B, B answers, A sends ACK
          for 200 and in some moment after that - disappears from
          network (for example - unplug network cable).</div>
        <div>After that B send BYE request.</div>
        <div> </div>
        <div>Parameters of proto_tcp:</div>
        <div>
          <div>modparam("proto_tcp", "tcp_port", 5060)</div>
          <div>modparam("proto_tcp", "tcp_send_timeout", 5000)</div>
          <div>modparam("proto_tcp", "tcp_async", 1)</div>
          <div>modparam("proto_tcp", "tcp_crlf_pingpong", 0)</div>
          <div> </div>
        </div>
        <div> </div>
        <div>Expected behavior:</div>
        <div>1. if TCP session is still active: opensips will try to
          send BYE to A via TCP and close TCP-connection after 5000ms
          (tcp_send_timeout interval), send 477 Send Failed to himself
          and 408 to B, as result of BYE transaction.</div>
        <div>2. if TCP session is no active (after some TCP-FIN):
          opensips will try to re-establish TCP session, and if it will
          be not successfull - send 477 Send Failed to himself and 408
          to B, as result of BYE transaction.</div>
        <div> </div>
        <div>Real behavior:</div>
        <div>TCP session is active (there was no TCP-FIN), next
          OPTIONS-ping from opensips is not answered by A (because he
          disappeared from network) on TCP-level (no TCP-ACK for request
          with options), opensips starts to send TCP-retransminnions of
          last OPTIONS request (and continue to send this
          retransmissions in a next few minutes), not trying to send BYE
          request at all, not trying to close TCP session. After
          fr_timeout number of  seconds opensips sends 408 to B as
          result of BYE transaction and not sends 477 to himself.</div>
        <div> </div>
        <div>There is screenshot of my example:</div>
        <div><a rel="noopener noreferrer"
            href="https://imgur.com/HNxwxPo" moz-do-not-send="true">https://imgur.com/HNxwxPo</a></div>
        <div> </div>
        <div>So - it looks like opensips totally ignore tcp_send_timeout
          value and it leads to some misbehavior in handling TCP
          requests. Am i right or i missed something?</div>
      </div>
      <div xmlns="http://www.w3.org/1999/xhtml"> </div>
      <div xmlns="http://www.w3.org/1999/xhtml"> </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>