<p>Experiencing an issue with QMalloc when Kamailio receives a lot of subscriptions (dialog-info) in a short period of time. The following is reported in logs and the TCP (TLS) connection fails:</p>

<p><code>Apr  4 18:06:04 ua-proxy-01 /usr/local/sbin/kamailio[28456]: ERROR: <core> [tcp_main.c:959]: tcpconn_new(): mem. allocation failure<br>
Apr  4 18:06:04 ua-proxy-01 /usr/local/sbin/kamailio[28456]: ERROR: <core> [tcp_main.c:3977]: handle_new_connect(): tcpconn_new failed, closing socket</code></p>

<p>A snapshot of SHM usage from around the time of the connection is as follows:</p>

<p><code>shmem:fragments = 39604<br>
shmem:free_size = 49473400<br>
shmem:max_used_size = 67108696<br>
shmem:real_used_size = 17635464<br>
shmem:total_size = 67108864<br>
shmem:used_size = 9423760</code></p>

<p>Kamailio <code>-I</code> output is as follows:</p>

<p><code>Print out of kamailio internals<br>
  Version: kamailio 4.3.4 (x86_64/linux) b2843e<br>
  Default config: /usr/local/etc/kamailio/kamailio.cfg<br>
  Default paths to modules: /usr/local/lib64/kamailio/modules<br>
  Compile flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, DBG_QM_MALLOC, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES<br>
  MAX_RECV_BUFFER_SIZE=262144<br>
  MAX_LISTEN=16<br>
  MAX_URI_SIZE=1024<br>
  BUF_SIZE=65535<br>
  DEFAULT PKG_SIZE=8MB<br>
  DEFAULT SHM_SIZE=64MB<br>
  ADAPTIVE_WAIT_LOOPS=1024<br>
  TCP poll methods: poll, epoll_lt, epoll_et, sigio_rt, select<br>
  Source code revision ID: b2843e<br>
  Compiled with: gcc 4.7.2<br>
  Compiled on: 17:56:04 Apr  4 2016<br>
Thank you for flying kamailio!</code></p>

<p>Once it has gotten in this state, TCP connections will no longer work, regardless of how low the SHM gets. Other connections (UDP) and subscriptions (dialog-info) work correctly at this time. There are no other OOM errors in the logs. The only thing that will resolve the issue is to restart Kamailio.</p>

<p>Compiling to use FMalloc (<code>MEMMNG=0 MEMDBG=1 make cfg</code>) appears to resolve the issue. Kamailio <code>-I</code> output as follows:</p>

<p><code>Print out of kamailio internals<br>
  Version: kamailio 4.3.4 (x86_64/linux) b2843e<br>
  Default config: /usr/local/etc/kamailio/kamailio.cfg<br>
  Default paths to modules: /usr/local/lib64/kamailio/modules<br>
  Compile flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, F_MALLOC, DBG_F_MALLOC, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES<br>
  MAX_RECV_BUFFER_SIZE=262144<br>
  MAX_LISTEN=16<br>
  MAX_URI_SIZE=1024<br>
  BUF_SIZE=65535<br>
  DEFAULT PKG_SIZE=8MB<br>
  DEFAULT SHM_SIZE=64MB<br>
  ADAPTIVE_WAIT_LOOPS=1024<br>
  TCP poll methods: poll, epoll_lt, epoll_et, sigio_rt, select<br>
  Source code revision ID: b2843e<br>
  Compiled with: gcc 4.7.2<br>
  Compiled on: 18:07:19 Apr  4 2016<br>
Thank you for flying kamailio!</code></p>

<p>At the time the TCP connection works correctly, the SHM usage is:</p>

<p><code>shmem:fragments = 40669<br>
shmem:free_size = 51558136<br>
shmem:max_used_size = 67107816<br>
shmem:real_used_size = 15550728<br>
shmem:total_size = 67108864<br>
shmem:used_size = 10045520</code></p>

<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 or <a href="https://github.com/kamailio/kamailio/issues/562">view it on GitHub</a><img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZVKBpnHPlsKKIUhFbEe_dp6m-3Kuks5p0UlugaJpZM4H_Ugl.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/562"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>