[SR-Users] db_mysql "Commands out of sync; you can't run this command now "

MÉSZÁROS Mihály misi at niif.hu
Mon Aug 29 11:51:35 CEST 2011


Hi,

Your patch didn't work for me. The kamailio didn't start if i use "if ( 
_rank != PROC_MAIN)"
So i commented out, both if statement, and now "out of sync problem 
disappeared"

--- a/modules_k/usrloc/ul_mod.c
+++ b/modules_k/usrloc/ul_mod.c
@@ -355,8 +355,11 @@ static int child_init(int _rank)
                         break;
         }

-       if (!ul_dbh)
+LM_INFO("before misi ul_mod con: %p rank: %d",ul_dbh,_rank);
+//     if (!ul_dbh)
+//     if ( _rank != PROC_MAIN)
                 ul_dbh = ul_dbf.init(&db_url); /* Get a new database 
connection */
+LM_INFO("after misi ul_mod con: %p rank: %d",ul_dbh,_rank);
         if (!ul_dbh) {
                 LM_ERR("child(%d): failed to connect to database\n", 
_rank);
                 return -1;

BUT

I am experiencing that in usrloc module, still more then one worker 
process share the same sql connection:

Aug 29 11:16:04 hal /usr/sbin/kamailio[21521]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 1
Aug 29 11:16:04 hal /usr/sbin/kamailio[21523]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 3
Aug 29 11:16:04 hal /usr/sbin/kamailio[21525]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 5
Aug 29 11:16:04 hal /usr/sbin/kamailio[21521]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 1
Aug 29 11:16:04 hal /usr/sbin/kamailio[21524]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 4
Aug 29 11:16:04 hal /usr/sbin/kamailio[21527]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 7
Aug 29 11:16:04 hal /usr/sbin/kamailio[21522]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 2
Aug 29 11:16:04 hal /usr/sbin/kamailio[21526]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 6
Aug 29 11:16:04 hal /usr/sbin/kamailio[21530]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: -1
Aug 29 11:16:04 hal /usr/sbin/kamailio[21508]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 0
Aug 29 11:16:04 hal /usr/sbin/kamailio[21528]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: 8
Aug 29 11:16:04 hal /usr/sbin/kamailio[21523]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 3
Aug 29 11:16:04 hal /usr/sbin/kamailio[21524]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 4
Aug 29 11:16:04 hal /usr/sbin/kamailio[21525]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 5
Aug 29 11:16:04 hal /usr/sbin/kamailio[21528]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 8
Aug 29 11:16:04 hal /usr/sbin/kamailio[21522]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 2
Aug 29 11:16:04 hal /usr/sbin/kamailio[21526]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 6
Aug 29 11:16:04 hal /usr/sbin/kamailio[21529]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: (nil) rank: -1
Aug 29 11:16:04 hal /usr/sbin/kamailio[21527]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 7
Aug 29 11:16:04 hal /usr/sbin/kamailio[21508]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: 0
Aug 29 11:16:04 hal /usr/sbin/kamailio[21530]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: -1
Aug 29 11:16:04 hal /usr/sbin/kamailio[21529]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb7286d5c rank: -1
Aug 29 11:16:04 hal /usr/sbin/kamailio[21536]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: 0xb7286d5c rank: 12
Aug 29 11:16:04 hal /usr/sbin/kamailio[21534]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: 0xb7286d5c rank: 10
Aug 29 11:16:04 hal /usr/sbin/kamailio[21533]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: 0xb7286d5c rank: 9
Aug 29 11:16:04 hal /usr/sbin/kamailio[21533]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb72ab174 rank: 9
Aug 29 11:16:04 hal /usr/sbin/kamailio[21535]: INFO: usrloc 
[ul_mod.c:358]: before misi ul_mod con: 0xb7286d5c rank: 11
Aug 29 11:16:04 hal /usr/sbin/kamailio[21534]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb72ab174 rank: 10
Aug 29 11:16:04 hal /usr/sbin/kamailio[21536]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb72ab174 rank: 12
Aug 29 11:16:04 hal /usr/sbin/kamailio[21535]: INFO: usrloc 
[ul_mod.c:363]: after misi ul_mod con: 0xb72ab174 rank: 11


Misi


2011-08-28 13:45 keltezéssel, Alex Hermann írta:
> On Sunday 28 August 2011, MÉSZÁROS Mihály wrote:
>> I attached the log file.
>> If you need detailed log/higher log level, then please let me know.
> usrloc seems to be using the same connection from multiple processes:
>
> pid: 18389 and 18391, connection: 0xb7387d5c
>
>
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18389]: INFO: db_mysql [km_dbase.c:83]:  submit_query:  con: 0xb7387d5c  table: location  query: select
> contact,expires,q,callid,cseq,flags,cflags,user_agent,received,path,socket,methods,last_modified from location where username='mutf-hd' order by q
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18391]: INFO: db_mysql [km_dbase.c:83]:  submit_query:  con: 0xb7387d5c  table: location  query: select
> contact,expires,q,callid,cseq,flags,cflags,user_agent,received,path,socket,methods,last_modified from location where username='ppke-vjk' order by q
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18389]: INFO: db_mysql [km_dbase.c:177]: store_result:  con: 0xb7387d5c  table: location
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18389]: INFO: db_mysql [km_dbase.c:83]:  submit_query:  con: 0xb7387d5c  table: location  query: update location set expires='2011-08-28 12:45:10',q=-1.00
> ,cseq=2,flags=0,cflags=0,user_agent='Polycom HDX 8000 HD (Release - 3.0.2.1-17007)',received=NULL,path=NULL,socket='tcp:195.111.192.7:5060',methods=24575,last_modified='2011-08-28 12:40:10' where
> username='mutf-hd' AND contact='sip:mutf-hd at 193.225.216.28:5060;transport=tcp' AND callid='3533311123-1752'
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18391]: INFO: db_mysql [km_dbase.c:177]: store_result:  con: 0xb7387d5c  table: location
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18391]: INFO: db_mysql [km_dbase.c:83]:  submit_query:  con: 0xb7387d5c  table: location  query: insert into location
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18389]: INFO: db_mysql [km_dbase.c:83]:  submit_query:  con: 0xb7387d5c  table: location  query: select
> contact,expires,q,callid,cseq,flags,cflags,user_agent,received,path,socket,methods,last_modified from location where username='de-tek-hpc' order by q
> Aug 28 12:40:10 hal /usr/sbin/kamailio[18389]: ERROR: db_mysql [km_dbase.c:131]: driver error on query: Commands out of sync; you can't run this command now
>
>
> It probably needs a fix like below because mod_init has also created a db
> connection which is inherited by at least one child and ul_dbh is not 0 anymore.
> That process needs to be excluded from opening a database connection, all
> other childs need to open their own DB connection. I just don't know what
> rank mod_init is run as and thus don't know which process to exclude. Maybe
> some other dev can jump in.
>
>
> diff --git a/modules_k/usrloc/ul_mod.c b/modules_k/usrloc/ul_mod.c
> index b3a9499..ca50b01 100644
> --- a/modules_k/usrloc/ul_mod.c
> +++ b/modules_k/usrloc/ul_mod.c
> @@ -378,7 +378,7 @@ static int child_init(int _rank)
>                          break;
>          }
>
> -       if (!ul_dbh)
> +       if (rank != PROC_MAIN)
>                  ul_dbh = ul_dbf.init(&db_url); /* Get a new database connection */
>          if (!ul_dbh) {
>                  LM_ERR("child(%d): failed to connect to database\n", _rank);
>




More information about the sr-users mailing list