Bug #81184 MySQL crashed when make connections from daemon plugin
Submitted: 23 Apr 2016 8:28 Modified: 28 Jul 2016 4:31
Reporter: Fangxin Flou (OCA) Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:All OS:Any
Assigned to: CPU Architecture:Any

[23 Apr 2016 8:28] Fangxin Flou
Description:
I am writing a daemon plugin to gather some linux performance data into remote database, when make the "mysql_real_connect" call from daemon plugin, the server crashed with following errors.

Version: '5.6.30'  socket: '/tmp/mysql.sock'  port: 3306  (OneSQL) Source distribution
08:17:59 UTC - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68062 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x80000
/usr/local/onesql5630/bin/mysqld(my_print_stacktrace+0x2e)[0x87dcfe]
/usr/local/onesql5630/bin/mysqld(handle_fatal_signal+0x473)[0x62c303]
/lib64/libpthread.so.0[0x3763a0e7c0]
/usr/local/onesql5630/bin/mysqld(thd_increment_bytes_received+0x12)[0x66db62]
/usr/local/onesql5630/bin/mysqld[0x622fd7]
/usr/local/onesql5630/bin/mysqld[0x623968]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
160423 16:17:59 mysqld_safe Number of processes running now: 0
160423 16:17:59 mysqld_safe mysqld restarted

How to repeat:
Call mysql_real_connect function in a daemon plugin.

......

    if (!mysql_real_connect(db->conn, o_host,
        o_user, o_pass, o_dbid, atoi(o_port), NULL, CLIENT_REMEMBER_OPTIONS))
    {
        myError(db);
        mysql_close(db->conn);
        db->conn = NULL;
        return OCI_ERROR;
    }

......

Suggested fix:
sql_class.cc

original code:

void thd_increment_bytes_received(ulong length)
{
  current_thd->status_var.bytes_received+= length;
}

new code:

void thd_increment_bytes_received(ulong length)
{
  if (current_thd != NULL)
  current_thd->status_var.bytes_received+= length;
}

the daemon thread does not have THD class assigned, so the current_thd is null.
[28 Jul 2016 4:31] MySQL Verification Team
Hello Fangxin Flou,

Thank you for the report.
Could you please provide exact repeatable test case, and steps to reproduce this issue at our end? If you can provide more information, feel free to add it to this bug and change the status back to 'Open'.

Thanks,
Umesh