Re: dbpool problem

"Nikos Balkanas" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <7AAE73B73B594376BD042E479D27E3F7@tardis>
Hi,

It is to be expected. You need to synchronize your threads with a mutex. You are changing len or pos at another part of the program and you violate the assertion. Or better use gwlist_consume & gwlist_append, which lock pos.

BR,
Nikos
  ----- Original Message ----- 
  From: Esteban Cacavelos 
  To: devel Devel 
  Sent: Thursday, January 28, 2010 8:02 PM
  Subject: dbpool problem


  Hi Developers, i've been prooving the dbpool of kannel in the following scenario and i've found some problems

  static DBPool *pool3 = NULL; //GLOBAL

  //DATA BASE INIT
  void voDBInitalization()
  {
      CfgGroup *grp;
      Octstr *host, *username, *password, *database;
      long port;

      grp = cfg_get_single_group(cfg, octstr_imm("Database"));

      if((host = cfg_get(grp, octstr_imm("Host")))==NULL)
              panic(0, "Host");
      if((username = cfg_get(grp, octstr_imm("User")))==NULL)
              panic(0, "User");
      if((password = cfg_get(grp, octstr_imm("Password")))==NULL)
              panic(0, "passl");
      if((database = cfg_get(grp, octstr_imm("DBName")))==NULL)
              panic(0, "db");
      if (cfg_get_integer(&port, grp, octstr_imm("Port")) == -1)
              panic(0, "port");

          db_conf = gw_malloc(sizeof(DBConf));
      
          gw_assert(db_conf != NULL);
      
         db_conf->mysql = gw_malloc(sizeof(MySQLConf));
    
      gw_assert(db_conf->mysql != NULL);
    
          db_conf->mysql->host = host;
          db_conf->mysql->port = port;
          db_conf->mysql->username = username;
          db_conf->mysql->password = password;
          db_conf->mysql->database = database;

    

          pool = dbpool_create(DBPOOL_MYSQL, db_conf, 2);
    
      gw_assert(pool != NULL);
   }







  //MAIN
  int main (){

    threads[j++] = gwthread_create(thread1,&stParam);
                  threads[j++] = gwthread_create(thread2,&stParam);

  for (i = 0; i < j; ++i)
                          gwthread_join(threads[i]);
  } 





   thread1 and thread2 share the pool and try the query when dbpool_check returns >=1. 

  Both threads check the pool with dbpool_check(pool)  and its works correctly a few minutes but then the program throw panic because the function dbpool_check call
  pconn = gwlist_get(p->pool, i);  AND THE FOLLOWING CONDITION DOESN'T MATCH gw_assert(pos < list->len); in gwlist_get 


  I supose something like this is happening:  one thread get the len of the pool and then the other deletes one element when the dbpool_check try to re-establish some connection, so, the first thread has a inconsitent len of the pool.   



  i hope that i have explained the problem in the right way and sorry for the mistakes. 





  -- 
  Esteban L. Cacavelos de Amoriza
  Cel: 0981 220 429
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.