← Back to team overview

maria-developers team mailing list archive

Re: mysql_stmt_prepare_start returns with error code 2006


András Szabó <andrei.hu@xxxxxxxxx> writes:

> I am currently working on a c++11 asio based async connector for
> mariadb. The library takes advantage of mariadb’s async interface
> (mysql_*_start, mysql_*_cont functions). The whole point would be to
> prevent blocking in mysql operations and make operations cancellable via a
> reasonable interface.

Sounds great! The basic _start()/_cont() interface, while flexible, is
somewhat low-level, and higher-level interfaces should be very useful.

Note BTW. that such connector should work just as well for connecting to a
MySQL server (using the mariadb client library), as the async interface does
not require anything special server-side.

> Some example code:
> TEST_CASE("tmp3") {
>     init_db();
>     asio::io_service io;
>     amdb::connector conn(io);
>     bool saved = false;
>     entity e(42, 3.14, "our entity");
>     amdb::auth_info auth("root");
>     conn.async_connect(amdb::null_endpoint, "edbtest", auth, amdb::default_flags, [&] (const std::error_code& ec) {
>         REQUIRE(!ec);
>         conn.async_write_entity(e, [&] (const std::error_code &ec) {
>             INFO(ec);
>             REQUIRE(!ec);
>             if (!ec) {
>                 saved = true;
>             }
>             io.stop();
>         });
>     });
>     io.run();
>     REQUIRE(saved);
> }
> async_write_entity() is an extra feature of the lib, which is generating
> an sql “batch” of prepared statements to persist hierarchical objects and
> executes that batch.
> Unfortunately I am receiving an error 2006 from my very first
> mysql_stmt_prepare call. This error roughly translates to "connection to
> mysql server is gone”. I cannot really spot the issue with my operation,
> could someone give me a hint about this error (typical causes, what to
> check, etc etc.)? I am a bit clueless here how to tackle this problem.

If you get "connection gone" on the very first operation, the most likely
explanation seems to be that the MYSQL * connection object is not handled
correctly in your code.

One possibility could be that your async_connect() code completes too early?
If mysql_stmt_prepare_start() runs before mysql_real_connect_cont() has
returned zero, then maybe an error 2006 could result, the connection not
having been set up yet.

Probably you should start by getting something simpler to work. The async
and non-async functions can be mixed. So you could try something like
amdc::connector::async_connect() and then just calling something simple like
mysql_select_db() (non-async) afterwards. And get that working first.

Then you can try to get non-async mysql_stmt_prepare() working. And next you
can try with mysql_select_db_start() and _cont() to test simple async
operations. And finally you can re-try with mysql_stmt_prepare_start().

Hopefully, with smaller steps it will be easier to understand what the root
cause of your problem is. Of course, feel free to ask again for more
detailed help; starting with something simpler will also make it easier for
you to provide more details on the issue to assist in tracking it down.

 - Kristian.

Follow ups