<p>Hi,</p>

<p>In the load_dialog_info_from_db function (dlg_db_handler.c), the following block may be problematic:</p>

<p>dlg-&gt;h_id = hash_id;<br>
next_id = d_table-&gt;entries[dlg-&gt;h_entry].next_id;<br>
d_table-&gt;entries[dlg-&gt;h_entry].next_id = (next_id &lt; dlg-&gt;h_id) ? (dlg-&gt;h_id + 1) : next_id;</p>

<p>At startup, assume d_table-&gt;entries[5].next_id is initialized at 25 (see function init_dlg_table in dlg_hash.c) and assume you have only one dialog in the database with hash_entry=5 and hash_id=25. Since the condition next_id &lt; dlg-&gt;h_id is false (because next_id == dlg-&gt;h_id == 25), the next available hash_id for a future dialog that matches this entry will be 25. Therefore, there will be duplicated (hash_entry,hash_id) which will cause errors when the dialog is inserted in the database.</p>

<p>I guess replacing the condition next_id &lt; dlg-&gt;h_id by next_id =&lt; dlg-&gt;h_id should solve the issue?</p>

<p>Regards,<br>
Mickael</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/OpenSIPS/opensips/issues/304">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/5479561__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNDAxNjI5NSwiZGF0YSI6eyJpZCI6Mzk5ODYxNzV9fQ==--24f3c53697bbe24150c59084b51a3b20cfcacabe.gif" width="1" /></p>