[sr-dev] [tracker] Task opened: Sometimes some kamailio processes eat 100% CPU

sip-router bugtracker at sip-router.org
Tue May 27 11:01:10 CEST 2014


THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below. 

User who did this - Maxim (simax) 

Attached to Project - sip-router
Summary - Sometimes some kamailio processes eat 100% CPU
Task Type - Bug Report
Category - Module
Status - Unconfirmed
Assigned To - 
Operating System - All
Severity - Medium
Priority - Normal
Reported Version - Development
Due in Version - Undecided
Due Date - Undecided
Details - Some time ago we had some problems with our MysSQL server and some kamailio processes were got stuck and ate 100% CPU. We use sqlops module to call mysql procedure. The procedure returns two results (a result set and status of the "CALL" command).

It seems there is a bug in db_mysql module in file km_dbase.c, function db_mysql_store_result(..). The bug is in incorrect using of MysQL API function mysql_next_result(..). That function is used to skip rest of results returned by DB query (because mysql connection is opened with flag CLIENT_MULTI_STATEMENTS). Part of the code that causes the problem is

<code>#if (MYSQL_VERSION_ID >= 40100)
	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) > 0 ) {
		MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
		mysql_free_result(res);
	}
#endif</code>

According MySQL doc, return values for mysql_next_result(..) can be the following: 

 0  - Successful and there are more results
 -1 - Successful and there are no more results
 >0 - An error occured

Thus, if there will be an error when reading a next result, the code will be infinitely looped in "while" cycle and current process will eat 100% CPU (The mysql_more_results will not help here because it just checks a local flag that will be set to TRUE in cases when there will be more than one result).

The solution is to replace " > 0" with " == 0":

<code>#if (MYSQL_VERSION_ID >= 40100)
	while( mysql_more_results(CON_CONNECTION(_h)) && mysql_next_result(CON_CONNECTION(_h)) == 0 ) {
		MYSQL_RES *res = mysql_store_result( CON_CONNECTION(_h) );
		mysql_free_result(res);
	}
#endif</code>

More information can be found at the following URL:
http://sip-router.org/tracker/index.php?do=details&task_id=434

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.



More information about the sr-dev mailing list