<p>Hello,</p>
<p>I am going to take a step back here; it might be best to address the following  issue that i have found (which is very much related to the one at hand) before proceeding to the issue in this ticket.</p>
<p>Regarding the following statements i made in this ticket:  "In issue 1681 there is code that allows Kamailio to start even if a database connection can not be established. Queries attempting to run against the offline database fail gracefully. And once the database is back online, a connection is established and queries against it are successful.".</p>
<p>Those statements are indeed true;  however, what i have noticed is that if i leave the database offline and another unrelated query using another unrelated database handle via sqlops executes, the program crashes.  This other database handle is to a database that is connected to upon startup and is online, however it appears from kamailio's logs and the gdb output that the code thinks this particular online database is not online and attempts a reconnect (at which point the program crashes).  And so we have the following scenario:  one database offline;  another online;  test query to the offline database is gracefully rejected;  but a query to the online database crashes kamailio.</p>
<p>So, the setup is this:<br>
leave a database offline (shut down)<br>
start up kamailio<br>
kamailio starts even though the database is offline which is good<br>
my test query begins to execute against the offline database and kamailio reacts gracefully to not<br>
being able to submit the queries to the offline database.  also good.<br>
now, if another entirely unrelated query is executed (a query against an online database for example),<br>
the program crashes.<br>
I figure it might be best to tackle this issue first before addressing the one originally referenced in this ticket which is where the program crashes when a database engine is shutdown during normal call processing.</p>
<p>Here is the output of gdb for the issue where the database remains offline from start to end.</p>
<p>(gdb) bt<br>
#0  0x0000000000000000 in ?? ()<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="31891578" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/1" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/1/hovercard" href="https://github.com/kamailio/kamailio/issues/1">#1</a>  0x00002ba7077959fb in sql_reconnect (sc=0x2ba5e34aac10) at sql_api.c:187<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="41491271" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/2" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/2/hovercard" href="https://github.com/kamailio/kamailio/pull/2">#2</a>  0x00002ba7077a3448 in sql_check_connection (dbl=0x2ba5e34aac10) at sqlops.c:234<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="48744343" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/3" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/3/hovercard" href="https://github.com/kamailio/kamailio/pull/3">#3</a>  0x00002ba7077a3765 in sql_query (msg=0x2ba5e3b59178, dbl=0x2ba5e34aac10 "(\253J\343\245+", query=0x2ba5e3b79c10 "\320\335c\343\245+",<br>
res=0x2ba5e35f87d0 "\257\242\376h") at sqlops.c:247<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="49856885" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/4" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/4/hovercard" href="https://github.com/kamailio/kamailio/pull/4">#4</a>  0x0000000000433f19 in do_action (h=0x7fff05edb820, a=0x2ba5e363e800, msg=0x2ba5e3b59178) at core/action.c:1085<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="51480460" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/5" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/5/hovercard" href="https://github.com/kamailio/kamailio/issues/5">#5</a>  0x00000000004414df in run_actions (h=0x7fff05edb820, a=0x2ba5e363e800, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="51489870" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/6" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/6/hovercard" href="https://github.com/kamailio/kamailio/issues/6">#6</a>  0x0000000000441bd6 in run_actions_safe (h=0x7fff05ede060, a=0x2ba5e363e800, msg=0x2ba5e3b59178) at core/action.c:1625<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="51492477" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/7" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/7/hovercard" href="https://github.com/kamailio/kamailio/issues/7">#7</a>  0x00000000004dd859 in lval_pvar_assign (h=0x7fff05ede060, msg=0x2ba5e3b59178, lv=0x2ba5e363e688, rv=0x2ba5e363f450) at core/lvalue.c:284<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="51499233" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/8" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/8/hovercard" href="https://github.com/kamailio/kamailio/issues/8">#8</a>  0x00000000004dbf19 in lval_assign (h=0x7fff05ede060, msg=0x2ba5e3b59178, lv=0x2ba5e363e688, rve=0x2ba5e363f448) at core/lvalue.c:400<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="51703057" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/9" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/9/hovercard" href="https://github.com/kamailio/kamailio/issues/9">#9</a>  0x000000000043f14d in do_action (h=0x7fff05ede060, a=0x2ba5e363de48, msg=0x2ba5e3b59178) at core/action.c:1443<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="52436308" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/10" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/10/hovercard" href="https://github.com/kamailio/kamailio/pull/10">#10</a> 0x00000000004414df in run_actions (h=0x7fff05ede060, a=0x2ba5e363d3f8, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="52569646" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/11" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/11/hovercard" href="https://github.com/kamailio/kamailio/issues/11">#11</a> 0x00000000004305a6 in do_action (h=0x7fff05ede060, a=0x2ba5e390da70, msg=0x2ba5e3b59178) at core/action.c:691<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="52744476" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/12" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/12/hovercard" href="https://github.com/kamailio/kamailio/pull/12">#12</a> 0x00000000004414df in run_actions (h=0x7fff05ede060, a=0x2ba5e3907958, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="52784350" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/13" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/13/hovercard" href="https://github.com/kamailio/kamailio/pull/13">#13</a> 0x00000000004305a6 in do_action (h=0x7fff05ede060, a=0x2ba5e3989260, msg=0x2ba5e3b59178) at core/action.c:691<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="52819753" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/14" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/14/hovercard" href="https://github.com/kamailio/kamailio/pull/14">#14</a> 0x00000000004414df in run_actions (h=0x7fff05ede060, a=0x2ba5e3989260, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="52852064" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/15" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/15/hovercard" href="https://github.com/kamailio/kamailio/issues/15">#15</a> 0x0000000000441bd6 in run_actions_safe (h=0x7fff05ee1920, a=0x2ba5e3989260, msg=0x2ba5e3b59178) at core/action.c:1625<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53297477" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/16" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/16/hovercard" href="https://github.com/kamailio/kamailio/pull/16">#16</a> 0x00000000005843e0 in rval_get_int (h=0x7fff05ee1920, msg=0x2ba5e3b59178, i=0x7fff05ede768, rv=0x2ba5e39893b8, cache=0x0) at core/rvalue.c:915<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53387906" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/17" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/17/hovercard" href="https://github.com/kamailio/kamailio/pull/17">#17</a> 0x0000000000586d00 in rval_expr_eval_int (h=0x7fff05ee1920, msg=0x2ba5e3b59178, res=0x7fff05ede768, rve=0x2ba5e39893b0) at core/rvalue.c:1913<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53397137" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/18" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/18/hovercard" href="https://github.com/kamailio/kamailio/pull/18">#18</a> 0x0000000000587133 in rval_expr_eval_int (h=0x7fff05ee1920, msg=0x2ba5e3b59178, res=0x7fff05edf0e0, rve=0x2ba5e3989ae0) at core/rvalue.c:1921<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53511603" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/19" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/19/hovercard" href="https://github.com/kamailio/kamailio/pull/19">#19</a> 0x0000000000433810 in do_action (h=0x7fff05ee1920, a=0x2ba5e398a448, msg=0x2ba5e3b59178) at core/action.c:1043<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53562369" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/20" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/20/hovercard" href="https://github.com/kamailio/kamailio/pull/20">#20</a> 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e398a448, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53562546" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/21" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/21/hovercard" href="https://github.com/kamailio/kamailio/issues/21">#21</a> 0x00000000004305a6 in do_action (h=0x7fff05ee1920, a=0x2ba5e350f4f0, msg=0x2ba5e3b59178) at core/action.c:691<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53569003" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/22" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/22/hovercard" href="https://github.com/kamailio/kamailio/pull/22">#22</a> 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e350f4f0, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53897061" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/23" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/23/hovercard" href="https://github.com/kamailio/kamailio/pull/23">#23</a> 0x0000000000433ccc in do_action (h=0x7fff05ee1920, a=0x2ba5e3513e28, msg=0x2ba5e3b59178) at core/action.c:1058<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="53988785" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/24" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/24/hovercard" href="https://github.com/kamailio/kamailio/issues/24">#24</a> 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e3503118, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54025498" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/25" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/25/hovercard" href="https://github.com/kamailio/kamailio/pull/25">#25</a> 0x0000000000433ccc in do_action (h=0x7fff05ee1920, a=0x2ba5e35141b0, msg=0x2ba5e3b59178) at core/action.c:1058<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54052425" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/26" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/26/hovercard" href="https://github.com/kamailio/kamailio/pull/26">#26</a> 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e34ccb70, msg=0x2ba5e3b59178) at core/action.c:1564<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54054848" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/27" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/27/hovercard" href="https://github.com/kamailio/kamailio/pull/27">#27</a> 0x0000000000441cad in run_top_route (a=0x2ba5e34ccb70, msg=0x2ba5e3b59178, c=0x0) at core/action.c:1646<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54070295" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/28" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/28/hovercard" href="https://github.com/kamailio/kamailio/pull/28">#28</a> 0x0000000000545339 in receive_msg (<br>
buf=0x595f530 "REGISTER sip:pipeline.bbpsphone.net SIP/2.0\r\nVia: SIP/2.0/TLS 10.65.5.1:27155;branch=z9hG4bK9QDJ45PWpBmNPe21;rport\r\nContact: <sip:259ef72cf54b2a6.79355009@10.65.5.1:27155;rinstance=377AD7AA;transport="..., len=948, rcv_info=0x2ba6070bb358) at core/receive.c:340<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54103137" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/29" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/29/hovercard" href="https://github.com/kamailio/kamailio/issues/29">#29</a> 0x0000000000640719 in receive_tcp_msg (<br>
tcpbuf=0x2ba6070bb638 "REGISTER sip:pipeline.bbpsphone.net SIP/2.0\r\nVia: SIP/2.0/TLS 10.65.5.1:27155;branch=z9hG4bK9QDJ45PWpBmNPe21;rport\r\nContact: <sip:259ef72cf54b2a6.79355009@10.65.5.1:27155;rinstance=377AD7AA;transport="..., len=948, rcv_info=0x2ba6070bb358, con=0x2ba6070bb340) at core/tcp_read.c:1448<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54127057" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/30" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/30/hovercard" href="https://github.com/kamailio/kamailio/issues/30">#30</a> 0x00000000006426b0 in tcp_read_req (con=0x2ba6070bb340, bytes_read=0x7fff05ee2444, read_flags=0x7fff05ee243c) at core/tcp_read.c:1631<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54173812" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/31" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/31/hovercard" href="https://github.com/kamailio/kamailio/pull/31">#31</a> 0x000000000064c49d in handle_io (fm=0x2ba5e3ba3d50, events=1, idx=-1) at core/tcp_read.c:1862<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54286524" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/32" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/32/hovercard" href="https://github.com/kamailio/kamailio/issues/32">#32</a> 0x00000000006505d8 in io_wait_loop_epoll (h=0xad0bc0, t=2, repeat=0) at core/io_wait.h:1061<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54658436" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/33" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/33/hovercard" href="https://github.com/kamailio/kamailio/issues/33">#33</a> 0x0000000000645f12 in tcp_receive_loop (unix_sock=37) at core/tcp_read.c:1974<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54659447" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/34" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/34/hovercard" href="https://github.com/kamailio/kamailio/issues/34">#34</a> 0x000000000063347a in tcp_init_children () at core/tcp_main.c:5083<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54659806" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/35" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/35/hovercard" href="https://github.com/kamailio/kamailio/issues/35">#35</a> 0x0000000000425978 in main_loop () at main.c:1728<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="54659913" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/36" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/36/hovercard" href="https://github.com/kamailio/kamailio/issues/36">#36</a> 0x000000000042bd72 in main (argc=13, argv=0x7fff05ee2de8) at main.c:2666</p>
<p>(gdb) frame 1<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="31891578" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/1" data-hovercard-type="issue" data-hovercard-url="/kamailio/kamailio/issues/1/hovercard" href="https://github.com/kamailio/kamailio/issues/1">#1</a>  0x00002ba7077959fb in sql_reconnect (sc=0x2ba5e34aac10) at sql_api.c:187<br>
187             sc->dbh = sc->dbf.init(&sc->db_url);<br>
(gdb) list<br>
182             }<br>
183             if (sc->dbh!=NULL) {<br>
184                     /* already connected */<br>
185                     return 0;<br>
186             }<br>
187             sc->dbh = sc->dbf.init(&sc->db_url);<br>
188             if (sc->dbh==NULL) {<br>
189                     LM_ERR("failed to connect to the database [%.*s]\n",<br>
190                                             sc->name.len, sc->name.s);<br>
191                     return -1;</p>
<p>(gdb) frame 2<br>
<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="41491271" data-permission-text="Issue title is private" data-url="https://github.com/kamailio/kamailio/issues/2" data-hovercard-type="pull_request" data-hovercard-url="/kamailio/kamailio/pull/2/hovercard" href="https://github.com/kamailio/kamailio/pull/2">#2</a>  0x00002ba7077a3448 in sql_check_connection (dbl=0x2ba5e34aac10) at sqlops.c:234<br>
234             if(sql_reconnect(dbl)<0) {<br>
(gdb) list<br>
229                     LM_CRIT("no database handle with reconnect disabled\n");<br>
230                     return -1;<br>
231             }<br>
232<br>
233         LM_DBG("try to establish SQL connection\n");<br>
234             if(sql_reconnect(dbl)<0) {<br>
235                     LM_ERR("failed to connect to database\n");<br>
236                     return -1;<br>
237             }<br>
238             return 0;</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, <a href="https://github.com/kamailio/kamailio/issues/1821#issuecomment-460406826">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZZuMCSzRyp-t-tE2VYusSFm6p6Vgks5vKJxogaJpZM4aPgQx">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZTdRzX-wySpALSyupQJQ172XcwoHks5vKJxogaJpZM4aPgQx.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":"PERSON","message":"@srinikart in #1821: Hello,\r\n\r\nI am going to take a step back here; it might be best to address the following  issue that i have found (which is very much related to the one at hand) before proceeding to the issue in this ticket.   \r\n\r\nRegarding the following statements i made in this ticket:  \"In issue 1681 there is code that allows Kamailio to start even if a database connection can not be established. Queries attempting to run against the offline database fail gracefully. And once the database is back online, a connection is established and queries against it are successful.\".   \r\n\r\nThose statements are indeed true;  however, what i have noticed is that if i leave the database offline and another unrelated query using another unrelated database handle via sqlops executes, the program crashes.  This other database handle is to a database that is connected to upon startup and is online, however it appears from kamailio's logs and the gdb output that the code thinks this particular online database is not online and attempts a reconnect (at which point the program crashes).  And so we have the following scenario:  one database offline;  another online;  test query to the offline database is gracefully rejected;  but a query to the online database crashes kamailio.\r\n \r\nSo, the setup is this:   \r\n   leave a database offline (shut down)  \r\n   start up kamailio\r\n   kamailio starts even though the database is offline which is good  \r\n   my test query begins to execute against the offline database and kamailio reacts gracefully to not \r\n   being able to submit the queries to the offline database.  also good.   \r\n   now, if another entirely unrelated query is executed (a query against an online database for example), \r\n   the program crashes.   \r\nI figure it might be best to tackle this issue first before addressing the one originally referenced in this ticket which is where the program crashes when a database engine is shutdown during normal call processing.\r\n\r\nHere is the output of gdb for the issue where the database remains offline from start to end.  \r\n\r\n(gdb) bt\r\n#0  0x0000000000000000 in ?? ()\r\n#1  0x00002ba7077959fb in sql_reconnect (sc=0x2ba5e34aac10) at sql_api.c:187\r\n#2  0x00002ba7077a3448 in sql_check_connection (dbl=0x2ba5e34aac10) at sqlops.c:234\r\n#3  0x00002ba7077a3765 in sql_query (msg=0x2ba5e3b59178, dbl=0x2ba5e34aac10 \"(\\253J\\343\\245+\", query=0x2ba5e3b79c10 \"\\320\\335c\\343\\245+\",\r\n    res=0x2ba5e35f87d0 \"\\257\\242\\376h\") at sqlops.c:247\r\n#4  0x0000000000433f19 in do_action (h=0x7fff05edb820, a=0x2ba5e363e800, msg=0x2ba5e3b59178) at core/action.c:1085\r\n#5  0x00000000004414df in run_actions (h=0x7fff05edb820, a=0x2ba5e363e800, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#6  0x0000000000441bd6 in run_actions_safe (h=0x7fff05ede060, a=0x2ba5e363e800, msg=0x2ba5e3b59178) at core/action.c:1625\r\n#7  0x00000000004dd859 in lval_pvar_assign (h=0x7fff05ede060, msg=0x2ba5e3b59178, lv=0x2ba5e363e688, rv=0x2ba5e363f450) at core/lvalue.c:284\r\n#8  0x00000000004dbf19 in lval_assign (h=0x7fff05ede060, msg=0x2ba5e3b59178, lv=0x2ba5e363e688, rve=0x2ba5e363f448) at core/lvalue.c:400\r\n#9  0x000000000043f14d in do_action (h=0x7fff05ede060, a=0x2ba5e363de48, msg=0x2ba5e3b59178) at core/action.c:1443\r\n#10 0x00000000004414df in run_actions (h=0x7fff05ede060, a=0x2ba5e363d3f8, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#11 0x00000000004305a6 in do_action (h=0x7fff05ede060, a=0x2ba5e390da70, msg=0x2ba5e3b59178) at core/action.c:691\r\n#12 0x00000000004414df in run_actions (h=0x7fff05ede060, a=0x2ba5e3907958, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#13 0x00000000004305a6 in do_action (h=0x7fff05ede060, a=0x2ba5e3989260, msg=0x2ba5e3b59178) at core/action.c:691\r\n#14 0x00000000004414df in run_actions (h=0x7fff05ede060, a=0x2ba5e3989260, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#15 0x0000000000441bd6 in run_actions_safe (h=0x7fff05ee1920, a=0x2ba5e3989260, msg=0x2ba5e3b59178) at core/action.c:1625\r\n#16 0x00000000005843e0 in rval_get_int (h=0x7fff05ee1920, msg=0x2ba5e3b59178, i=0x7fff05ede768, rv=0x2ba5e39893b8, cache=0x0) at core/rvalue.c:915\r\n#17 0x0000000000586d00 in rval_expr_eval_int (h=0x7fff05ee1920, msg=0x2ba5e3b59178, res=0x7fff05ede768, rve=0x2ba5e39893b0) at core/rvalue.c:1913\r\n#18 0x0000000000587133 in rval_expr_eval_int (h=0x7fff05ee1920, msg=0x2ba5e3b59178, res=0x7fff05edf0e0, rve=0x2ba5e3989ae0) at core/rvalue.c:1921\r\n#19 0x0000000000433810 in do_action (h=0x7fff05ee1920, a=0x2ba5e398a448, msg=0x2ba5e3b59178) at core/action.c:1043\r\n#20 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e398a448, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#21 0x00000000004305a6 in do_action (h=0x7fff05ee1920, a=0x2ba5e350f4f0, msg=0x2ba5e3b59178) at core/action.c:691\r\n#22 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e350f4f0, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#23 0x0000000000433ccc in do_action (h=0x7fff05ee1920, a=0x2ba5e3513e28, msg=0x2ba5e3b59178) at core/action.c:1058\r\n#24 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e3503118, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#25 0x0000000000433ccc in do_action (h=0x7fff05ee1920, a=0x2ba5e35141b0, msg=0x2ba5e3b59178) at core/action.c:1058\r\n#26 0x00000000004414df in run_actions (h=0x7fff05ee1920, a=0x2ba5e34ccb70, msg=0x2ba5e3b59178) at core/action.c:1564\r\n#27 0x0000000000441cad in run_top_route (a=0x2ba5e34ccb70, msg=0x2ba5e3b59178, c=0x0) at core/action.c:1646\r\n#28 0x0000000000545339 in receive_msg (\r\n    buf=0x595f530 \"REGISTER sip:pipeline.bbpsphone.net SIP/2.0\\r\\nVia: SIP/2.0/TLS 10.65.5.1:27155;branch=z9hG4bK9QDJ45PWpBmNPe21;rport\\r\\nContact: \u003csip:259ef72cf54b2a6.79355009@10.65.5.1:27155;rinstance=377AD7AA;transport=\"..., len=948, rcv_info=0x2ba6070bb358) at core/receive.c:340\r\n#29 0x0000000000640719 in receive_tcp_msg (\r\n    tcpbuf=0x2ba6070bb638 \"REGISTER sip:pipeline.bbpsphone.net SIP/2.0\\r\\nVia: SIP/2.0/TLS 10.65.5.1:27155;branch=z9hG4bK9QDJ45PWpBmNPe21;rport\\r\\nContact: \u003csip:259ef72cf54b2a6.79355009@10.65.5.1:27155;rinstance=377AD7AA;transport=\"..., len=948, rcv_info=0x2ba6070bb358, con=0x2ba6070bb340) at core/tcp_read.c:1448\r\n#30 0x00000000006426b0 in tcp_read_req (con=0x2ba6070bb340, bytes_read=0x7fff05ee2444, read_flags=0x7fff05ee243c) at core/tcp_read.c:1631\r\n#31 0x000000000064c49d in handle_io (fm=0x2ba5e3ba3d50, events=1, idx=-1) at core/tcp_read.c:1862\r\n#32 0x00000000006505d8 in io_wait_loop_epoll (h=0xad0bc0, t=2, repeat=0) at core/io_wait.h:1061\r\n#33 0x0000000000645f12 in tcp_receive_loop (unix_sock=37) at core/tcp_read.c:1974\r\n#34 0x000000000063347a in tcp_init_children () at core/tcp_main.c:5083\r\n#35 0x0000000000425978 in main_loop () at main.c:1728\r\n#36 0x000000000042bd72 in main (argc=13, argv=0x7fff05ee2de8) at main.c:2666\r\n\r\n(gdb) frame 1\r\n#1  0x00002ba7077959fb in sql_reconnect (sc=0x2ba5e34aac10) at sql_api.c:187\r\n187             sc-\u003edbh = sc-\u003edbf.init(\u0026sc-\u003edb_url);\r\n(gdb) list\r\n182             }\r\n183             if (sc-\u003edbh!=NULL) {\r\n184                     /* already connected */\r\n185                     return 0;\r\n186             }\r\n187             sc-\u003edbh = sc-\u003edbf.init(\u0026sc-\u003edb_url);\r\n188             if (sc-\u003edbh==NULL) {\r\n189                     LM_ERR(\"failed to connect to the database [%.*s]\\n\",\r\n190                                             sc-\u003ename.len, sc-\u003ename.s);\r\n191                     return -1;\r\n\r\n(gdb) frame 2\r\n#2  0x00002ba7077a3448 in sql_check_connection (dbl=0x2ba5e34aac10) at sqlops.c:234\r\n234             if(sql_reconnect(dbl)\u003c0) {\r\n(gdb) list\r\n229                     LM_CRIT(\"no database handle with reconnect disabled\\n\");\r\n230                     return -1;\r\n231             }\r\n232\r\n233         LM_DBG(\"try to establish SQL connection\\n\");\r\n234             if(sql_reconnect(dbl)\u003c0) {\r\n235                     LM_ERR(\"failed to connect to database\\n\");\r\n236                     return -1;\r\n237             }\r\n238             return 0;\r\n\r\n\r\n\r\n"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1821#issuecomment-460406826"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1821#issuecomment-460406826",
"url": "https://github.com/kamailio/kamailio/issues/1821#issuecomment-460406826",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>