Too many connections

Too many connections

am 01.06.2005 02:36:08 von Ronny Melz

Dear all,

I have a problem with the mysql interface for c, which after a couple of hours
thinking about bad or faulty programming are eliminated with probability
almost 100%.

within a loop, I do a mysql_query(), which is executed and I poll the result
and everything is fine. Up to when max_connections of the mysqld is reached:
each of the queries leaves after executing a sleeping mysql process behind on
the server, which hence throws the "Too many connections" error (or under
certain conditions even a "Can't create TCP/IP socket (24)").

Just because of this problem I recently upgraded mysql (including the
libraries) from 4.0.21 to 4.1.12, but the problem persisted.

Does anybody have an idea of how to solve this problem?
Any suggestions are appreciated.

Best,
Ronny


p.s.: code
#define GET_W_NR \
"select wort_nr from wortliste where wort_bin='%s' limit 1"
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *query;

init...
{
mysql_init(&mysql);
if ( !mysql_real_connect( &mysql, "127.0.0.1", "username", "passwd",
"dbase",
0, "/var/lib/mysql/mysql.sock", 0 ) )
{
fprintf(stderr, "Failed: %s\n", mysql_error(&mysql));
}
if (!(query = (char*) malloc(256*sizeof(char)))) fprintf(stderr, "no
pointer");
}

this is called in a loop and returns with an error after `max_connections`
cycles:
{
sprintf(query, GET_W_NR, refWort);
if ( mysql_query( &mysql, query ) )
{
fprintf(stderr, "query failed: %s\n", mysql_error(&mysql));
return 0;
}
if ( !( res = mysql_store_result( &mysql ) ) )
{fprintf(stderr, "store failed: %s\n", mysql_error(&mysql)); return
0;}
if ( row = mysql_fetch_row( res ) )
ref_word_nr = atoi(row[0]);
else
{fprintf(stderr, "fetch failed: %s\n", mysql_error(&mysql)); return
0;}
mysql_free_result(res);
}

exit...
free(query);
mysql_close(&mysql);

--
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe: http://lists.mysql.com/bugs?unsub=gcdmb-bugs@m.gmane.org

Re: Too many connections

am 01.06.2005 09:26:09 von Paul Coldrey

Hi Ronny,

To save an email from the mysql big-wigs I'll start with their standard
line that "this list is dedicated to repeatable test cases". I strongly
suspect they would not see you post as suitably complete to show the
presence a bug and allow it to be repeated. Perhaps your message would
be better posted to the users list.

Having said that, here are some thoughts that might help you:

The API I have has a function mysql_reap_query(...) which seems to be
entirely undocumented, but the source code offers this pearl:

/* send the query and return so we can do something else */
/* needs to be followed by *mysql_reap_query*() when we want to finish
processing it */

It appears this function may be deprecated?? If so it raises the
question of how does the server know when to free the data created by:

mysql_query( &mysql, query )

It may be the call to:

res = mysql_store_result( &mysql )

triggers the clean up,.. but this doesn't seem intuitive (to me).



Ronny Melz wrote:

> Dear all,
>
>I have a problem with the mysql interface for c, which after a couple of hours
>thinking about bad or faulty programming are eliminated with probability
>almost 100%.
>
>within a loop, I do a mysql_query(), which is executed and I poll the result
>and everything is fine. Up to when max_connections of the mysqld is reached:
>each of the queries leaves after executing a sleeping mysql process behind on
>the server, which hence throws the "Too many connections" error (or under
>certain conditions even a "Can't create TCP/IP socket (24)").
>
>Just because of this problem I recently upgraded mysql (including the
>libraries) from 4.0.21 to 4.1.12, but the problem persisted.
>
>Does anybody have an idea of how to solve this problem?
>Any suggestions are appreciated.
>
>Best,
>Ronny
>
>
>p.s.: code
>#define GET_W_NR \
>"select wort_nr from wortliste where wort_bin='%s' limit 1"
>MYSQL mysql;
>MYSQL_RES *res;
>MYSQL_ROW row;
>char *query;
>
>init...
> {
> mysql_init(&mysql);
> if ( !mysql_real_connect( &mysql, "127.0.0.1", "username", "passwd",
>"dbase",
> 0, "/var/lib/mysql/mysql.sock", 0 ) )
> {
> fprintf(stderr, "Failed: %s\n", mysql_error(&mysql));
> }
> if (!(query = (char*) malloc(256*sizeof(char)))) fprintf(stderr, "no
>pointer");
> }
>
>this is called in a loop and returns with an error after `max_connections`
>cycles:
>{
> sprintf(query, GET_W_NR, refWort);
> if ( mysql_query( &mysql, query ) )
> {
> fprintf(stderr, "query failed: %s\n", mysql_error(&mysql));
> return 0;
> }
> if ( !( res = mysql_store_result( &mysql ) ) )
> {fprintf(stderr, "store failed: %s\n", mysql_error(&mysql)); return
>0;}
> if ( row = mysql_fetch_row( res ) )
> ref_word_nr = atoi(row[0]);
> else
> {fprintf(stderr, "fetch failed: %s\n", mysql_error(&mysql)); return
>0;}
> mysql_free_result(res);
>}
>
>exit...
> free(query);
> mysql_close(&mysql);
>
>
>



--
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe: http://lists.mysql.com/bugs?unsub=gcdmb-bugs@m.gmane.org