<p></p>
<h3>Description</h3>
<p>The ACK that response to 200 OK was NAT relayed by Kamailio if using TCP protocol, then got this issue from log<br>
<code>pending write on new connection 0x14a595095d40 sock 16 (-1/539 bytes written) (err: 11 - Resource temporarily unavailable)</code></p>

<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<ul>
<li>Using KAMI with Lua for routing config.</li>
<li>make call between 2 sip clients, the receiver has been registered with TCP</li>
</ul>
<h4>Debugging Data</h4>
<ul>
<li>With the same scenario with UDP, it work fine.</li>
<li></li>
</ul>

<pre><code>(paste your debugging data here)
</code></pre>
<h4>Log Messages</h4>

<pre><code>Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <script>: ROUTE RELAY BEGIN:-----------------------------------------------------------
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: tm [t_lookup.c:1327]: t_newtran(): msg (0x14a5999f0b38) id=3/4784 global id=2/4784 T start=0xffffffffffffffff
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: tm [t_lookup.c:497]: t_lookup_request(): start searching: hash=41830, isACK=1
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: tm [t_lookup.c:455]: matching_3261(): RFC3261 transaction matching failed - via branch [z9hG4bKQe8H61SrNcaXD]
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: tm [t_lookup.c:675]: t_lookup_request(): no transaction found
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: tm [t_funcs.c:286]: t_relay_to(): forwarding ACK statelessly
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/crypto/md5utils.c:67]: MD5StringArray(): MD5 calculated: 66c47e5249a7009267e0cd264863c247
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/msg_translator.c:1797]: check_boundaries(): no multi-part body
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/forward.c:577]: forward_request(): Sending:#012ACK sip:Joe%20Biden@14.186.XXX.XX:60791;transport=TCP SIP/2.0#015#012Via: SIP/2.0/TCP 188.166.XXX.XX:5060;branch=z9hG4bK663a.66c47e5249a7009267e0cd264863c247.0#015#012Via: SIP/2.0/UDP 127.0.0.2;received=127.0.0.2;rport=5060;branch=z9hG4bKQe8H61SrNcaXD#015#012Max-Forwards: 69#015#012From: "Donald Trump"
 <sip:33123456789@127.0.0.2>;tag=mUNavKm60XZte#015#012To: <sip:5512345@127.0.0.3:5060;transport=udp>;tag=bd21bf6b#015#012Call-ID: 0e846d85-720e-123a-45a5-ea0e9328da5f#015#012CSeq: 39612479 ACK#015#012Contac
t: <sip:gw+KamGW@127.0.0.2:5060;transport=udp;gw=KamGW>#015#012Content-Length: 0#015#012#015#012.
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/forward.c:578]: forward_request(): orig. len=557, new_len=539, proto=2
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: app_lua [app_lua_api.c:489]: sr_lua_reload_script(): No need to reload [/path-to-lua/routing.lua] is version 0
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: app_lua [app_lua_api.c:673]: app_lua_run_ex(): executing Lua function: [[ksr_onsend_route]]
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: app_lua [app_lua_api.c:675]: app_lua_run_ex(): lua top index is: 0
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/tcp_main.c:1993]: tcp_send(): no open tcp connection found, opening new one
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/ip_addr.c:577]: print_ip(): tcpconn_new: new tcp connection: 14.186.47.222
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/tcp_main.c:1175]: tcpconn_new(): on port 60791, type 2, socket -1
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/tcp_main.c:1494]: tcpconn_add(): hashes: 1566:2785:0, 4
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: <core> [core/tcp_main.c:2886]: tcpconn_1st_send(): pending write on new connection 0x14a595095d40 sock 16 (-1/539 bytes written) (err: 11 - Resource temporar
ily unavailable)
Aug  7 10:35:53 testnode1 /usr/local/sbin/kamailio[4806]: DEBUG: <core> [core/tcp_main.c:3792]: handle_ser_child(): read response= 14a595095d40, 5, fd 55 from 12 (4784)
Aug  7 10:35:53 testnode1 /usr/local/sbin/kamailio[4806]: DEBUG: <core> [core/io_wait.h:375]: io_watch_add(): DBG: io_watch_add(0x55f0338266a0, 55, 2, 0x14a595095d40), fd_no=41
Aug  7 10:35:53 testnode1 testnode[4784]: DEBUG: app_lua [app_lua_api.c:1003]: sr_kemi_lua_exec_func_ex(): param[0] for: xdbg is str: ROUTE RELAY END:--------------------------------------------------------
---

</code></pre>
<h4>SIP Traffic</h4>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/85822466/128597726-0f64fdec-9b45-4ef6-b480-f5c0b3f21600.png"><img src="https://user-images.githubusercontent.com/85822466/128597726-0f64fdec-9b45-4ef6-b480-f5c0b3f21600.png" alt="image" style="max-width:100%;"></a></p>
<pre><code>(paste your sip traffic here)
</code></pre>
<h3>Possible Solutions</h3>

<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>kamailio -v
version: kamailio 5.5.1 (x86_64/linux) 7abebb
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: 7abebb 
compiled on 07:46:14 Jun 27 2021 with gcc 8.3.0
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<p>Debian 10.10</p>
<pre><code>root@testnode1:~# uname -a
Linux testnode1 4.19.0-12-cloud-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2814">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZLQD2NY6FMRMSN2FGTT3UHHBANCNFSM5BXJTNTA">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email">Android</a>.<img src="https://github.com/notifications/beacon/ABO7UZN5SO3FBZQQA45DSF3T3UHHBA5CNFSM5BXJTNTKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4OLJMUQQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2814",
"url": "https://github.com/kamailio/kamailio/issues/2814",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>