From notifications@github.com Mon Oct 29 20:50:10 2018 From: mihovilkolaric To: sr-dev@lists.kamailio.org Subject: Re: [sr-dev] [kamailio/kamailio] sqlops blocks startup of kamailio if database unreachable (#1681) Date: Mon, 29 Oct 2018 12:50:01 -0700 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0412766554==" --===============0412766554== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi, thanks for the responses.=20 While I agree that the default behavior makes fully sense for most (or nearly= all) modules, still there are usecases where a more tolerant handling would = be nice. In my case, this is a multi-node homer-installation (as advised here: https:/= /github.com/sipcapture/homer/issues/254 ) - the kamailio (used as sipcapture-= server) uses a local sipcapture database, but all nodes share the same statis= tics database (accessed by sqlops) - in case the statistics-DB is not reachab= le temporarily during startup, I'd rather keep the sipcapture DB (and lose th= e statistics) than blocking startup of kamailio and losing both. I'm not experienced in kamailio-development, still I tried to implement that = functionality - in https://github.com/kamailio/kamailio/blob/master/src/modul= es/sqlops/sqlops.c I changed the static int child_init(int rank) to always re= turn 0 (regardless of the return-value of sql_connect() ): ``` static int child_init(int rank) { if (rank=3D=3DPROC_INIT || rank=3D=3DPROC_MAIN || rank=3D=3DPROC_TCP_= MAIN) return 0; int sql_result =3D sql_connect(); LM_INFO("SQL result: %d \n", sql_result); return 0; }=20 ``` The effect was, that kamailio starts even if the database is not reachable (a= nd sql_connect() returns -1): ``` INFO: sqlops [sqlops.c:156]: child_init(): SQL result: -1 ERROR: db_postgres [km_pg_con.c:115]: db_postgres_new_connection(): could not= connect to server: Connection refused ERROR: db_postgres [km_pg_con.c:148]: db_postgres_new_connection(): cleaning = up 0x7f858b5d6f88=3Dpkg_free() ERROR: [db.c:318]: db_do_init2(): could not add connection to the pool ERROR: sqlops [sql_api.c:164]: sql_connect(): failed to connect to the databa= se [cb] INFO: sqlops [sqlops.c:156]: child_init(): SQL result: -1 INFO: ctl [io_listener.c:210]: io_listen_loop(): io_listen_loop: using epoll_= lt as the io watch method (auto detected) ERROR: db_postgres [km_pg_con.c:115]: db_postgres_new_connection(): could not= connect to server: Connection refused ERROR: db_postgres [km_pg_con.c:148]: db_postgres_new_connection(): cleaning = up 0x7f858b5d6f88=3Dpkg_free() ERROR: [db.c:318]: db_do_init2(): could not add connection to the pool ERROR: sqlops [sql_api.c:164]: sql_connect(): failed to connect to the databa= se [cb] INFO: sqlops [sqlops.c:156]: child_init(): SQL result: -1 INFO: