<p></p>

<h3>Description</h3>
<p>ims_registrar_pcscf module create a process with rank 1 (PROC_SIPINIT) if reginfo flag is open..</p>
<p>This is wrong because it is written that PROC_SIPINIT rank  should be given  only to the first worker process.</p>
<pre><code>#define PROC_SIPINIT      1  /**< First (special) SIP worker - some modules do
                                                special processing in this child, like loading db data */
</code></pre>
<p>This leads to a problem.  ims_usrloc_pcscf loads registration records from the db twice.</p>
<p>The codes are demonstrated below.</p>
<p>Similar old issue exists here for another module:<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="205931377" data-permission-text="Title is private" data-url="https://github.com/kamailio/kamailio/issues/975" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/975/hovercard" href="https://github.com/kamailio/kamailio/issues/975">#975</a></p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>

<h4>Debugging Data</h4>

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

<p>Here are fork operations and their ranks:</p>
<pre><code>[root@n5gc-ims-dev src]# cat /usr/src/erhan5.log | grep init_mod_child | grep ims_usrloc_pcscf
 0(10662) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 0 rank -127: ims_usrloc_pcscf [main]
 1(10671) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 1 rank 1: ims_usrloc_pcscf [udp receiver child=0 sock=10.10.12.101:5060 (172.30.65.101:5060)]
 3(10673) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 3 rank 3: ims_usrloc_pcscf [udp receiver child=2 sock=10.10.12.101:5060 (172.30.65.101:5060)]
 2(10672) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 2 rank 2: ims_usrloc_pcscf [udp receiver child=1 sock=10.10.12.101:5060 (172.30.65.101:5060)]
 5(10675) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 5 rank -1: ims_usrloc_pcscf [slow timer]
 0(10662) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 0 rank 0: ims_usrloc_pcscf [main]
 6(10679) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 6 rank -1: ims_usrloc_pcscf [timer]
 4(10674) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 4 rank 4: ims_usrloc_pcscf [udp receiver child=3 sock=10.10.12.101:5060 (172.30.65.101:5060)]
 7(10680) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 7 rank -1: ims_usrloc_pcscf [secondary timer]
 8(10686) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 8 rank 1: ims_usrloc_pcscf [RegInfo Event Processor]
 9(10687) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 9 rank -1: ims_usrloc_pcscf [Dialog Clean Timer]
10(10688) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 10 rank -2: ims_usrloc_pcscf [ctl handler]
11(10689) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 11 rank 5: ims_usrloc_pcscf [tcp receiver (generic) child=0]
12(10694) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 12 rank 6: ims_usrloc_pcscf [tcp receiver (generic) child=1]
13(10695) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 13 rank 7: ims_usrloc_pcscf [tcp receiver (generic) child=2]
14(10697) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 14 rank 8: ims_usrloc_pcscf [tcp receiver (generic) child=3]
15(10699) DEBUG: <core> [core/sr_module.c:845]: init_mod_child(): idx 15 rank -4: ims_usrloc_pcscf [tcp main process]

</code></pre>
<h4>SIP Traffic</h4>

<pre><code>(paste your sip traffic here)
</code></pre>
<h3>Possible Solutions</h3>

<p>In following code ims_registrar_pcscf module create a process with rank 1 (PROC_SIPINIT) :<br>
fork_process(PROC_SIPINIT, "RegInfo Event Processor", 1);</p>
<pre><code>
static int child_init(int rank)
{

        LM_DBG("Initialization of module in child [%d] \n", rank);
    if ((subscribe_to_reginfo == 1) && (rank == PROC_MAIN)) {
             LM_DBG("Creating RegInfo Event Processor process\n");
            int pid = fork_process(PROC_SIPINIT, "RegInfo Event Processor", 1);
            if (pid < 0)
                return -1; //error
            if (pid == 0) {
                if (cfg_child_init())
                    return -1; //error
                reginfo_event_process();
            }
        }
    
        if (rank == PROC_MAIN || rank == PROC_TCP_MAIN)
                return 0;
        if (rank == 1) {
                /* init stats */
                //TODO if parameters are modified via cfg framework do i change them?
                //update_stat( max_expires_stat, default_registrar_cfg.max_expires ); update_stat( max_contacts_stat, default_registrar_cfg.max_contacts ); update_stat( default_expire_stat, default_registrar_cfg.default_expires );
        }

        /* don't do anything for main process and TCP manager process */
        if (rank == PROC_MAIN || rank == PROC_TCP_MAIN)
                return 0;

        return 0;
}
</code></pre>
<p>Here is how ims_usrloc_pcscf loads records from db at its child init callback function:</p>
<pre><code> if (_rank==PROC_SIPINIT && db_mode!=DB_ONLY) {
                // if cache is used, populate domains from DB
                for( ptr=root ; ptr ; ptr=ptr->next) {
                        LM_DBG("Preloading domain %.*s\n", ptr->name.len, ptr->name.s);
                        if (preload_udomain(ul_dbh, ptr->d) < 0) {
                                LM_ERR("child(%d): failed to preload domain '%.*s'\n",
                                                _rank, ptr->name.len, ZSW(ptr->name.s));
                                return -1;
                        }
                }
        }
</code></pre>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code> it exists at latest version on master branch.
[here](https://github.com/kamailio/kamailio/blob/master/src/modules/ims_registrar_pcscf/ims_registrar_pcscf_mod.c#L328)
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>CentOS 7.1
</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/2809">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZP77FQKX4B27Q72O73T2KFQPANCNFSM5BILOKTA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZMUFST5LHNALYP2WGDT2KFQPA5CNFSM5BILOKTKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4OIFTLRQ.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/2809",
"url": "https://github.com/kamailio/kamailio/issues/2809",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>