Bug #13768 Embedded MySQL Server is not re-entrant. (crashes)
Submitted: 5 Oct 2005 10:49 Modified: 24 Nov 2006 13:45
Reporter: Gary Ashford Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S4 (Feature request)
Version:5.0.13 rc OS:Windows (Win 2000)
Assigned to: CPU Architecture:Any

[5 Oct 2005 10:49] Gary Ashford
Description:
The embedded MySQL server is not re-entrant, i.e. it cannot be re-initialised once the mysql_server_end() command has been called.  Trying to call mysql_server_init() again results in a crash.

How to repeat:
#include "stdafx.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>
#include <mysql.h>

MYSQL *mysql;

static char *server_options[] = { "mysql_test", "--defaults-file=c:/mysql/my.cnf" };
int num_elements = sizeof(server_options)/ sizeof(char *);

static char *server_groups[] = { "libmysqld_server", "libmysqld_client" };

int main(void)
{
   mysql_server_init(num_elements, server_options, server_groups);
   mysql = mysql_init(NULL);
   mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
   mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);

   mysql_real_connect(mysql, NULL,NULL,NULL, "tester", 0,NULL,0);

   mysql_close(mysql);
   mysql_server_end();

	 mysql_server_init(num_elements, server_options, server_groups); //crashes here
   mysql = mysql_init(NULL);
   mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
   mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);

   mysql_real_connect(mysql, NULL,NULL,NULL, "tester", 0,NULL,0);

   mysql_close(mysql);
   mysql_server_end();

   return 0;
}
[5 Oct 2005 11:06] Vasily Kishkin
Thanks for test case. I was not able to reproduce the bug on 5.0.14 rc. Could you please verify your test case on 5.0.14 rc ?
[5 Oct 2005 13:43] Vasily Kishkin
Sorry my mistake. I was able to reproduce the bug. I need to analyze the bug more.
[5 Oct 2005 14:40] Heikki Tuuri
Hi!

InnoDB is not re-entrant in the embedded server. Unfortunately, it is not even in the TODO to make it re-entrant. Why would you want to shut down the embedded server and start it again in the lifetime of the process?

Regards,

Heikki
[5 Oct 2005 15:52] Gary Ashford
Our application instanciates the server process dynamically under the control of commands written in our 4GL. Since we have no control of how end-users write their apps, it is entirely probable that a user may intentionally (or accidentally) terminate the server process and then try to re-start it again.
Whether the embedded server is re-entrant or not, it should certainly not crash when an attempt is made to re-start it!
This is not a TODO, but more of a general stability issue.  I hope you will agree.