MySQL multithreading app and sigfault when reconnect to MySQL into worker thread
Posted by: Alexandre Kalendarev
Date: April 01, 2013 06:10AM

0 down vote favorite

I have multithreading application client to MySQL and I use MySQL C-client (libmysqlclient_r). I have db connections pool, where I open connection before create thread workers (pthread_create).

The each worker gets only single connection from connections pool before starting the work and puts it to the pool after finishing work. The each worker use it's unique connection.

But, database server is very overload, and MySQL client have errors: MySQL " Lost connection to MySQL server during query" or " MySQL server has gone away". My application make reconnect in the worker thread:

my_bool res = mysql_ping(c->mysql);
if (res) {

    c->mysql = mysql_init(NULL);

    struct conn_desc *cd = &c->db->cds[c->num];
    syslog(LOG_ERR, "reconnect :[%s:%d]\t%s\tnew MySQL=%X tid=%X\n", cd->host,  cd->port, c->db->default_db_name, c->mysql, pthread_self());

    res = mysql_real_connect(c->mysql, cd->host, cd->login, cd->passwd, c->db->default_db_name, cd->port, NULL, 0);
    if (res == NULL) {
        syslog(LOG_ERR, "[restart ] reconnect Error\n");

Sometime, I have sigmentation fault into mysql_ping() or mysql_real_connect(). Why? I use the separate mysql-connections between workers threads. What is wrong? How is making the Right?

Options: ReplyQuote

Written By
MySQL multithreading app and sigfault when reconnect to MySQL into worker thread
April 01, 2013 06:10AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.