Bug #33854 client can crash during mysql_real_connect if the connection dies too fast
Submitted: 13 Jan 2008 19:49 Modified: 30 Jun 2009 18:14
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.1.23 OS:Windows
Assigned to: CPU Architecture:Any
Tags: mysql_real_connect

[13 Jan 2008 19:49] Shane Bester
Description:
If the connection is made, but dies quick enough due to whatever reason, a client crash can happen with stack trace:

libmysql.dll!my_real_read
libmysql.dll!my_net_read
libmysql.dll!cli_safe_read
libmysql.dll!mysql_real_connect
gypsy.exe!db_connect
gypsy.exe!db_pthread

In net_serv.cc the crash is here:

/* First read is done with non blocking mode */
 if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)
{
  my_bool interrupted = vio_should_retry(net->vio); <----------

vio_should_retry is a macro that dereferences vio, which is null in this crash.
In addition, the debug client prints out these messages:

Error: Freeing pointer out of range at line 231, '..\vio\vio.c'
Error: Freeing unallocated data at line 232, '..\vio\vio.c'

How to repeat:
I will upload a simple program that:
1) spawns some threads
2) each thread has auto-reconnect enabled
3) each thread tries to kill another thread using KILL <id>
[14 Jan 2008 13:48] MySQL Verification Team
Hmm, my simple test program doesn't crash. I'll have to spend the time debugging the original complex program to find out what's going wrong.
[6 Mar 2009 17:11] Andrew Hutchings
Could be a duplicate of bug #25532