CDR Mysql: Timeout When Remote Database Unavailable

Home » Asterisk Users » CDR Mysql: Timeout When Remote Database Unavailable
Asterisk Users 7 Comments

Hello,

I am using CDR mysql to log to remote server:

in modules.conf, I preload the modules:

[modules]
preload => cdr_mysql.so preload => app_mysql.so

and in cdr_mysql.conf, I have all the details defined (hostname, dbname, table, password, user, port).

In a situation when I start asterisk, and the remote database in unreachable, asterisk waits for several minutes before it actually starts (before it loads sip module, etc).

And when database is unreachable during operation, when call happens, sometimes the call is connected, other times it waits for mysql and call times out.

I assume there might be scenarios where CDR logging is essential, and calls should not be made without CDR functioning (ie for billing purposes). But this is not my situation. I would like CDR to log, but in a situation where database is temporarily unavailable, I don’t want that to prevent asterisk to function (ie, start, make calls)

Is there somewhere a timeout setting, that I could set to a low number, so that it times out quickly ?

or what would be the best solution in my case ?

thanks,

7 thoughts on - CDR Mysql: Timeout When Remote Database Unavailable

  • I would install a local copy of MySQL (to the same machine as Asterisk) so that it is definitely available, tell Asterisk to write to that, and then set up replication to the remote MySQL instance which is sometimes unavailable.

    Replication will sort itself out automatically after almost any duration of non-connectivity.

    If you are using MySQL, the traditional Master-Slave replication is easy to set up and works well. If you’re using MariaDB (which is installed in some distributions even when you ask for MySQL) then the new method of replication is Galera, although standard Master-Slave is still fully supported.

    Regards,

    Antony.


    If my advice was worth anything, I wouldn’t just give it away.

    Please reply to the list;
    please *don’t* CC me.

  • > That is an interesting suggestion, which I’ll consider.

    But I would still like to know where the Aterisk mysql timeout duration comes from, and whether it can be configured.

    thanks,

  • Isn’t the MySQL stuff deprecated in favor of odbc? You may be barking up the wrong tree if you plan to make source changes.

    j

  • In the case of cdr_mysql, the connect timeout is configurable by putting the following in cdr_mysql.conf:

    [global]
    timeout = 5 ; Set connect timeout to 5 seconds

    For app_mysql, setting the connection timeout is shown in the documentation:

    *CLI> core show application MYSQL

    Kind regards, Sean

  • OK, so i changed the timeout to 2 sec, but it does not have the desired effect. I expected, if mysql cannot be reached, after 2 seconds the call will progress normally.

    Instead, the call still terminates if mysql cannot be reached.

    Is it possible to set in asterisk, if mysql is unreachable then skip the step and simply ignore mysql logging ?

  • I just tested this, I’m using cdr_odbc, by shutting down mysql and I did not experience the call being dropped.

    The console logged the mysql failure, but the call continued.

    You may want to consider moving to cdr_odbc instead.

    Doug

  • That sounds different to me.

    The OP is asking about a call which starts at a time when MySQL is not available.

    It sounds as though you made a call, then terminated MySQL, and the call did not terminate.

    I certainly agree with that suggestion / recommendation.

    Antony.


    “Black holes are where God divided by zero.”

    – Steven Wright

    Please reply to the list;
    please *don’t* CC me.