<h3>Description</h3>
<p>Kamailio crashes while querying for unexpired contacts in a location table while it is saving contacts to db.<br>
Seems to be a regression, since this didn't happened with Kamailio 4.4.</p>
<h4>Reproduction</h4>
<p>Constantly flush many locations and simultaneously get location statistics from <code>usrloc</code> module via <code>kamcmd ul.db_users</code>:</p>
<div class="highlight highlight-source-shell"><pre>shell1 % <span class="pl-k">while</span> kamcmd ul.flush <span class="pl-k">;</span> <span class="pl-k">do</span> <span class="pl-c1">:</span> <span class="pl-k">;</span> <span class="pl-k">done</span></pre></div>
<div class="highlight highlight-source-shell"><pre>shell2 % curl -H content-type:<span class="pl-cce">\ </span>application/json -s -d <span class="pl-s"><span class="pl-pds">'</span>{"jsonrpc":"2.0", "method":"ul.db_contacts", "params": ["location"]}<span class="pl-pds">'</span></span> localhost:5060/JSONRPC</pre></div>
<h4>Debugging Data</h4>
<pre><code>#0  0x00007f600e3345ad in ul_rpc_db_contacts (rpc=0x7f6004f8b960 <func_param>, ctx=0x7f6004f8b8e0 <_jsonrpc_ctx>) at ul_rpc.c:774
#1  0x00007f6004d6c15c in jsonrpc_dispatch (msg=0x7ffc7fc4e250, s1=0x0, s2=0x0) at jsonrpcs_mod.c:1251
#2  0x000055c674d60eb9 in do_action (h=0x7ffc7fc4e170, a=0x7f6012607828, msg=0x7ffc7fc4e250) at core/action.c:1054
#3  0x000055c674d6ea4d in run_actions (h=0x7ffc7fc4e170, a=0x7f6012607828, msg=0x7ffc7fc4e250) at core/action.c:1552
#4  0x000055c674d60e25 in do_action (h=0x7ffc7fc4e170, a=0x7f6012607ac8, msg=0x7ffc7fc4e250) at core/action.c:1045
#5  0x000055c674d6ea4d in run_actions (h=0x7ffc7fc4e170, a=0x7f6012600b28, msg=0x7ffc7fc4e250) at core/action.c:1552
#6  0x000055c674d60e25 in do_action (h=0x7ffc7fc4e170, a=0x7f6012607d00, msg=0x7ffc7fc4e250) at core/action.c:1045
#7  0x000055c674d6ea4d in run_actions (h=0x7ffc7fc4e170, a=0x7f60125fecf8, msg=0x7ffc7fc4e250) at core/action.c:1552
#8  0x00007f6004f913b4 in xhttp_process_request (orig_msg=0x7f6012622410, new_buf=0x7f6012638ad0 "POST /JSONRPC HTTP/1.1\r\nVia: SIP/2.0/TCP 127.0.0.1:58590\r\nHost: localhost:5060\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nContent-Length: 67\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"jsonrpc\": \"2.0\", \"method\":\"ul.db_contacts\",\"params\":[\"location\"]}", new_len=256) at xhttp_mod.c:282
#9  0x00007f6004f9253b in xhttp_handler (msg=0x7f6012622410) at xhttp_mod.c:357
#10 0x000055c674e4be83 in nonsip_msg_run_hooks (msg=0x7f6012622410) at core/nonsip_hooks.c:111
#11 0x000055c674e944d7 in receive_msg (buf=0x7f5feac686a8 "POST /JSONRPC HTTP/1.1\r\nHost: localhost:5060\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nContent-Length: 67\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"jsonrpc\": \"2.0\", \"method\":\"ul.db_contacts\",\"params\":[\"location\"]}", len=222, rcv_info=0x7f5feac683c8) at core/receive.c:202
#12 0x000055c674f2e43c in receive_tcp_msg (tcpbuf=0x7f5feac686a8 "POST /JSONRPC HTTP/1.1\r\nHost: localhost:5060\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nContent-Length: 67\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"jsonrpc\": \"2.0\", \"method\":\"ul.db_contacts\",\"params\":[\"location\"]}", len=222, rcv_info=0x7f5feac683c8, con=0x7f5feac683b0) at core/tcp_read.c:1263
#13 0x000055c674f30a70 in tcp_read_req (con=0x7f5feac683b0, bytes_read=0x7ffc7fc4ee68, read_flags=0x7ffc7fc4ee6c) at core/tcp_read.c:1478
#14 0x000055c674f339bb in handle_io (fm=0x7f60126506b0, events=1, idx=-1) at core/tcp_read.c:1652
#15 0x000055c674f23d9b in io_wait_loop_epoll (h=0x55c6753e0fa0 <io_w>, t=2, repeat=0) at core/io_wait.h:1065
#16 0x000055c674f359b0 in tcp_receive_loop (unix_sock=54) at core/tcp_read.c:1822
#17 0x000055c674e14095 in tcp_init_children () at core/tcp_main.c:4802
#18 0x000055c674d216e1 in main_loop () at main.c:1713
#19 0x000055c674d286a9 in main (argc=13, argv=0x7ffc7fc4f4f8) at main.c:2642
</code></pre>
<h4>Log Messages</h4>
<pre><code>ERROR: usrloc [urecord.c:431]: wb_timer(): updating contact in db failed (aor: 1234@example.com)
ERROR: db_mysql [km_dbase.c:127]: db_mysql_submit_query(): driver error on query: Commands out of sync; you can't run this command now (2014)
ERROR: <core> [db_query.c:339]: db_do_update(): error while submitting query
ERROR: usrloc [ucontact.c:1378]: db_update_ucontact_instance(): updating database failed
</code></pre>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.0.7 (x86_64/linux)
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, 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_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 6.3.0
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>Debian 9.5
</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/1900">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZfXXsceqQEZI1omNdRiwKN8SKbM2ks5vY0v6gaJpZM4cA-rX">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZZDMb7K8Y-aqFO6wiK5DikZoLyYsks5vY0v6gaJpZM4cA-rX.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"usrloc: core dump (#1900)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1900"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1900",
"url": "https://github.com/kamailio/kamailio/issues/1900",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>