<h3>Description</h3>
<p>I´m using kamailio´s sqlops-module on a postgresql database.</p>
<p>If the database server gets unreachable during operation, sqlops detects this and tries to reconnect:</p>
<pre><code>14:40:48.784 WARNING: db_postgres [km_dbase.c:259]: db_postgres_submit_query(): postgres query command failed, connection status 1, error [no connection to the server]
14:40:48.784 DEBUG: db_postgres [km_dbase.c:262]: db_postgres_submit_query(): resetting the connection to postgress server
14:40:48.784 ERROR: db_postgres [km_dbase.c:267]: db_postgres_submit_query(): 0x7f80a8093680 PQsendQuery Error: could not connect to server: Connection refused
</code></pre>
<p>and finally, when the DB comes up again, succeeds in executing queries:</p>
<pre><code>14:41:39.738 WARNING: db_postgres [km_dbase.c:259]: db_postgres_submit_query(): postgres query command failed, connection status 1, error [SSL connection has been closed unexpectedly]
14:41:39.739 DEBUG: db_postgres [km_dbase.c:262]: db_postgres_submit_query(): resetting the connection to postgress server
14:41:39.810 DEBUG: db_postgres [km_dbase.c:249]: db_postgres_submit_query(): sending query ok: 0x7f80a8093680 (1) 
</code></pre>
<p>So, obviously the module can handle database outages well.</p>
<p>But if the DB is already down when kamailio is started, the cyclic reconnect does not work. Instead, kamailio fails to start immediately:</p>
<pre><code>14:57:54.187 CRITICAL: <core> [main.c:1614]: main_loop(): Cannot fork
14:57:54.188 DEBUG: db_postgres [km_pg_con.c:112]: db_postgres_new_connection(): PQconnectdbParams(0x136bfb0)
14:57:54.188 DEBUG: <core> [core/sr_module.c:938]: init_mod_child(): idx 12 rank -1: rtimer [timer]
14:57:54.188 DEBUG: <core> [core/sr_module.c:938]: init_mod_child(): idx 12 rank -1: sqlops [timer]
14:57:54.188 DEBUG: <core> [core/sr_module.c:708]: find_mod_export_record(): found export of <db_bind_api> in module db_postgres [/usr/lib64/kamailio/modules/db_postgres.so]
14:57:54.188 DEBUG: <core> [db.c:209]: db_bind_mod(): using db bind api for db_postgres
14:57:54.188 DEBUG: <core> [db.c:314]: db_do_init2(): connection 0x7f23c0154120 not found in pool
14:57:54.188 DEBUG: db_postgres [km_pg_con.c:56]: db_postgres_new_connection(): db_id = 0x7f23c0154120
14:57:54.188 DEBUG: db_postgres [km_pg_con.c:70]: db_postgres_new_connection(): 0x7f23c0154380=pkg_malloc(80)
14:57:54.188 DEBUG: db_postgres [km_pg_con.c:84]: db_postgres_new_connection(): opening connection: postgres://xxxx:xxxx@xxxxxxxxxxxxxxxxxx
14:57:54.188 DEBUG: db_postgres [km_pg_con.c:112]: db_postgres_new_connection(): PQconnectdbParams(0x13a41e0)
14:57:54.188 ERROR: db_postgres [km_pg_con.c:115]: db_postgres_new_connection(): could not connect to server: Connection refused Is the server running on host "xxxxxxxxxxxx" () and accepting TCP/IP connections on port 5432?
14:57:54.188 ERROR: db_postgres [km_pg_con.c:148]: db_postgres_new_connection(): cleaning up 0x7f23c0154380=pkg_free()
14:57:54.188 ERROR: <core> [db.c:318]: db_do_init2(): could not add connection to the pool
14:57:54.188 ERROR: sqlops [sql_api.c:164]: sql_connect(): failed to connect to the database [cb]
14:57:54.188 ERROR: <core> [core/sr_module.c:942]: init_mod_child(): error while initializing module sqlops (/usr/lib64/kamailio/modules/sqlops.so) (idx: 12 rank: -1 desc: [timer])
14:57:54.189 ERROR: <core> [core/pt.c:340]: fork_process(): init_child failed for process 12, pid 24036, "timer"
14:57:54.189 CRITICAL: <core> [main.c:1691]: main_loop(): cannot fork timer process
14:57:54.189 ALERT: <core> [main.c:743]: handle_sigs(): child process 24009 exited normally, status=255
14:57:54.190 ALERT: <core> [main.c:743]: handle_sigs(): child process 24010 exited normally, status=255
14:57:54.190 ALERT: <core> [main.c:743]: handle_sigs(): child process 24011 exited normally, status=255
14:57:54.191 ALERT: <core> [main.c:743]: handle_sigs(): child process 24013 exited normally, status=255
14:57:54.191 ALERT: <core> [main.c:743]: handle_sigs(): child process 24015 exited normally, status=255
14:57:54.191 ALERT: <core> [main.c:743]: handle_sigs(): child process 24019 exited normally, status=255
14:57:54.191 ALERT: <core> [main.c:743]: handle_sigs(): child process 24030 exited normally, status=255
14:57:54.192 INFO: <core> [main.c:771]: handle_sigs(): terminating due to SIGCHLD
14:57:54.192 INFO: <core> [main.c:826]: sig_usr(): signal 15 received
14:57:54.192 INFO: <core> [main.c:826]: sig_usr(): signal 15 received
</code></pre>
<h4>Reproduction</h4>
<ul>
<li>use kamailio-script with sqlops</li>
<li>stop kamailio</li>
<li>stop database</li>
<li>try to start kamailio</li>
</ul>
<h4>Log Messages</h4>
<p>see above</p>
<h3>Additional Information</h3>
<ul>
<li>
<p><strong>Kamailio Version</strong> - output of <code>kamailio -v</code><br>
kamailio 5.1.2 (x86_64/linux)</p>
</li>
<li>
<p><strong>Operating System</strong>:<br>
RHEL 7.4 on x86_64</p>
</li>
</ul>

<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/1681">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZRL7WfHE3epxaP_oWFhneR3qSzzBks5umQPzgaJpZM4XvXbj">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZX7GqQk9VYXVkZ8SseY0VwiXCyY6ks5umQPzgaJpZM4XvXbj.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://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"sqlops blocks startup of kamailio if database unreachable (#1681)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1681"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1681",
"url": "https://github.com/kamailio/kamailio/issues/1681",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "sqlops blocks startup of kamailio if database unreachable (#1681)",
"sections": [
{
"text": "",
"activityTitle": "**mihovilkolaric**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@mihovilkolaric",
"facts": [
{
"name": "Repository: ",
"value": "kamailio/kamailio"
},
{
"name": "Issue #: ",
"value": 1681
}
]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1681,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1681\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1681"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 398292707\n}"
}
],
"themeColor": "26292E"
}
]</script>