List:MySQL++« Previous MessageNext Message »
From:Earl Miles Date:November 17 2004 5:20pm
Subject:Re: Strange interaction problem with mysql++ and net-snmp
View as plain text  
After dealing with other problems for some time, I finally got back to 
this and tried Chris Frey's suggestion of recompiling the MySQL++ 
library, rather than using the RH9 RPM.

Since I was compiling from fresh, I used 1.7.21. After recompiling, I 
realized that nowhere in the Makefile was there an option to turn on 
thread-safe code, so I quickly hacked the Makefile to use -pthread (I 
dunno autoconf at all, and was more interested in expediency). (Sadly, 
-pthread is possibly only valid on Linux systems).

The test now works, and I do not seem to have problems with it in my 
application anymore.

Further, and this is too preliminary to say for sure, as it will take 
several days of testing to be able to say more certainly, but 
difficulties I've had with the STL allocators and threads may have gone 
away due to, I believe, that -pthread in the compile. My research has 
indicated that libraries compiled without thread support, which use the 
Standard Template Library, can cause race conditions within the STL 
std::allocator even if the rest of the code is compiled with thread support.

This note might be useful to others who have, in the past, asked about
the thread-safeness of MySQL++ and not received an answer. I will report 
again in a couple of weeks when I've had a more intensive series of 
tests. (The failure conditions I was running into happen only after many 
hours of continuous operations, unfortunately).

Earl Miles wrote:
> I have a program that is to use both MySQL++ and Net-SNMP. While using 
> them both alone, everything seems to run perfectly well, but when I put 
> them together I get some odd interaction problems.
> 
> If I open an SQL connection before I initialize SNMP, any query I run
> on that connection will throw an exception but there is no error message
> or mysql errno. This only occurs if I create the Connection object with
> the new operator; if I create it on the stack, this doesn't happen and
> everything works fine. So far. My actual program has been modified to
> make the Connection be created on the stack, but I don't particularly
> like it, given the way that code is structured.
> 
> If I initialize SNMP first, and then open the connection object, I get
> coredumps in the net-snmp library when it tries to malloc().
> 
> I've managed to isolate this into a small test program. I rewrote the
> test program to use just mysql without the C++ API to see if I could
> duplicate the problem, and I cannot, which is why I'm checking with this
> list first to see if anybody has either a) run into this before, or b)
> understands the mysql++ library well enough to have any idea where to
> even look next for what this problem might be.
> 
> This one's got me stumped. This would be easier to trace if I could 
> understand the nature of the problem a little better. With MySQL not
> returning any kind of error message, I don't have any insight as to
> what exactly is going wrong. This is where I'm really hoping someone
> will have some ideas.
> 
> I'm running on a pretty stock RedHat 9.0 server with 1.7.19 MySQL++,
> mysql-3.23.58-1.9 from RPM, and net-snmp-5.1.1 from tar. Oh, and 
> gcc-3.2.2-5.
> 
> I've attached the testfile that can make this fail (which includes
> an #ifdef as kind of a comment; the top one, using the new operator
> fails, the bottom one doesn't). The query included is arbitrary, I
> have yet to find a query to run that doesn't fail, so when compiling
> anyone can just fill in values from a database that happens to be
> handy. Here's the quick and dirty line I'm using to compile it:
> 
> g++ -g -O2 -o testprog test.cpp `net-snmp-config --libs` 
> -L/usr/lib/mysql -lmysqlclient -lmysqlpp  -I/usr/include/mysql++ 
> -I/usr/include/mysql -I/usr/local/include -Wno-deprecated
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> #include <mysql++.hh>
> #include <iostream>
> 
> extern "C" {
> #include <net-snmp/net-snmp-config.h>
> #include <net-snmp/net-snmp-includes.h>
> }
> 
> int main(int argc, char* argv[])
> {
> 
> #ifndef THISWAY
> 	Connection* confull = new Connection(use_exceptions);
> 	Connection& con = *confull;
> #else
> 	Connection con(use_exceptions);
> #endif
> 	con.connect("testdb", "localhost", "testuser", "testpass"); 
> 	std::cout << "MySQL info: " << con.host_info() 	<< std::endl;
> 
> 	init_snmp("test");
> 
> 	std::cout << "Ping result: " << con.ping() << std::endl;
> 	std::cout << "Sizeof con: " << sizeof con << std::endl;
> 
> 	try
> 	{
> 		std::string query = "select id from interface where interfacename = 'lo0'";
> 		std::cout << "Query: " << query << std::endl; 		
> 		Result res = con.store(query);
> 
> 		Row row = res[0];
> 		std::cout << "Num Rows: " << res.size() << std::endl;
> 	}
> 	catch (BadQuery &er) 
> 	{ // handle any connection or
> 							  // query errors that may come up
> 		std::cout << "Error: " << er.error << std::endl;
> 		std::cout << "MySQL errnum: " << con.errnum() << std::endl;
> 		return 0;
> 	} 
> 	catch (...)
> 	{
> 		std::cout << "Unhandled exception" << std::endl;
> 	}
> }
> 
> 
> 

Thread
Strange interaction problem with mysql++ and net-snmpEarl Miles27 Oct
  • Re: Strange interaction problem with mysql++ and net-snmpChris Frey29 Oct
  • Re: Strange interaction problem with mysql++ and net-snmpEarl Miles17 Nov
    • Re: Strange interaction problem with mysql++ and net-snmpWarren Young18 Nov