<h3>Description</h3>
<p>usrloc should not leave any ucontact behind when on DB_ONLY</p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<pre><code>event_route[usrloc:contact-expired] {
    $var(uri) = "sip:" + $ulc(exp=>aor) + "@localhost";
    xinfo("expired contact for $ulc(exp=>aor) uri:$var(uri)");
    reg_fetch_contacts("location", "$var(uri)", "caller");
    if($(ulc(caller=>count)) < 0) {
        xinfo("no more contacts for $ulc(exp=>aor)\n");
    } else {
        xinfo("$ulc(exp=>aor) has $(ulc(caller=>count)) contacts left\n");
    }
    return;
}
</code></pre>
<p>REGISTER a subscriber and let it expire</p>
<h4>Debugging Data</h4>
<p>after</p>
<pre><code>root@16d059a62a76:/code/utils/kamcmd# sh /kamdev/shm_dump.sh 1
      2  qm_status:           alloc'd from usrloc: dlist.c: new_dlist(557)
      2  qm_status:           alloc'd from usrloc: dlist.c: new_dlist(565)
      2  qm_status:           alloc'd from usrloc: ucontact.c: new_ucontact(96)
      2  qm_status:           alloc'd from usrloc: udomain.c: new_udomain(91)
      2  qm_status:           alloc'd from usrloc: udomain.c: new_udomain(98)
      2  qm_status:           alloc'd from usrloc: ul_callback.c: init_ulcb_list(45)
      2  qm_status:           alloc'd from usrloc: ul_callback.c: register_ulcb(94)
      6  qm_status:           alloc'd from usrloc: udomain.c: build_stat_name(56)
     10  qm_status:           alloc'd from usrloc: ../../core/ut.h: shm_str_dup(722)

</code></pre>
<h4>Log Messages</h4>
<pre><code>1(4112) DEBUG: usrloc [udomain.c:996]: udomain_contact_expired_cb(): calling contact expired records - cycle [1]
 1(4112) DEBUG: usrloc [ul_callback.h:83]: run_ul_callbacks(): contact=0x7f621e476bd0, callback type 8/8, id 0 entered
 1(4112) exec: *** cfgtrace:request_route=[usrloc:contact-expired] c=[/kamdev/kamailio.cfg] l=1015 a=63 n=assign
 1(4112) exec: *** cfgtrace:request_route=[usrloc:contact-expired] c=[/kamdev/kamailio.cfg] l=1016 a=25 n=xinfo
 1(4112) INFO: <script>: expired contact for 1001-whatever uri:sip:1001-whatever@localhost 1(4112) exec: *** cfgtrace:request_route=[usrloc:contact-expired] c=[/kamdev/kamailio.cfg] l=1017 a=27 n=reg_fetch_contacts
 1(4112) exec: *** cfgtrace:request_route=[usrloc:contact-expired] c=[/kamdev/kamailio.cfg] l=1022 a=16 n=if
 1(4112) exec: *** cfgtrace:request_route=[usrloc:contact-expired] c=[/kamdev/kamailio.cfg] l=1021 a=25 n=xinfo
 1(4112) INFO: <script>: 1001-whatever has 1 contacts left
 1(4112) exec: *** cfgtrace:request_route=[usrloc:contact-expired] c=[/kamdev/kamailio.cfg] l=1023 a=2 n=return

</code></pre>
<h3>Possible Solutions</h3>
<p>I think the problem resides on udomain_contact_expired_cb() and using get_urecord(). PR will follow.</p>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.4.0-dev0 (x86_64/linux) 075c74
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_BLACKLIST, 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: 075c74 
compiled on 10:36:45 Oct  3 2019 with gcc 8.3.0
</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/2089?email_source=notifications&email_token=ABO7UZKIUCU4LQLK7JDYZU3QMXNJLA5CNFSM4I5CELB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPMIIFA">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOQHXYQQDBBCBZ5TD3QMXNJLANCNFSM4I5CELBQ">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABO7UZK4ZZG4SHWDRJVW4F3QMXNJLA5CNFSM4I5CELB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPMIIFA.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/2089?email_source=notifications\u0026email_token=ABO7UZKIUCU4LQLK7JDYZU3QMXNJLA5CNFSM4I5CELB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPMIIFA",
"url": "https://github.com/kamailio/kamailio/issues/2089?email_source=notifications\u0026email_token=ABO7UZKIUCU4LQLK7JDYZU3QMXNJLA5CNFSM4I5CELB2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPMIIFA",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>