-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert failure in read_buffer.hpp at line 90 #380
Comments
just a bit of more information, the query in our case returns empty results. |
I am using mariadb server on linux. |
If the failure only happens sometimes, you may be violating this precondition. Remember that a single connection shouldn't be used to initiate any async operation until the one it's currently executing completes. To validate this hypothesis, you can add a flag that gets set when an operation starts and cleared when it finishes. If this is the case, you may need to introduce synchronization, maybe using a channel. Let me know if you need help with this. Let me know if it helps. Regards, |
okay let me verify and get back, thanks for the reply. |
Thanks again for the insights, indeed the parallel execution was the case, do you have any sample code on this channel stuff ? |
This has come up before, so I hope I can implement #367 for Boost 1.88. You need an object that provides asynchronous mutual exclusion (an async mutex, if you prefer). With ideas taken from the first 2 examples in this Asio page: asio::awaitable<void> coro_main(
mysql::tcp_connection& conn,
asio::experimental::channel<void()>& lock
)
{
// Claim the lock by sending a message to the channel. Since the
// channel signature is void(), there are no arguments to send in the
// message itself.
co_await lock.async_send();
// Issue the SQL query to the server
const char* sql = "SELECT 'Hello world!'";
mysql::results result;
co_await conn.async_execute(sql, result);
// Release the lock by receiving the message back again.
lock.try_receive([](auto...) {});
} The channel must be created like this: asio::experimental::channel<void()> lock(ctx, 1); // ctx is your io_context The idea is that you create a channel with a buffer size of 1 element. If the lock is free, the channel's buffer will be empty and Some notes:
Another option is using Boost.MySQL Regards, |
To make the code clean and easily understandable, I would go with the connection pool. please point me to the patches if any so that i could apply them on my local tree and get the feature. Hope, things are stable and robust. |
I'd recommend using the Boost 1.87 beta: https://archives.boost.io/beta/1.87.0.beta1/source/boost_1_87_0_b1_rc2.tar.gz This is how I'd use the pool: // In main
// Pool configuration
mysql::pool_params params {
.server_address = mysql::host_and_port("your-hostname"),
.username = "your-username",
.password = "your-password",
.database = "your-database",
.max_size = 1, // Set to the max number of connections you want. You probably want more than 1
};
// Create the pool
mysql::connection_pool pool (ctx, std::move(params));
// Run it. Only needed once per pool
pool.async_run(asio::detached);
// Call pool.cancel() to make run exit when your program
// needs to quit, e.g. from a signal handler
asio::awaitable<void> coro_main(
mysql::connection_pool& pool
)
{
// Get a connection. This is a proxy to an any_connection.
// If all connections are in use, this will wait until one is free.
// By default, this waits forever, so it may be adequate to set a timeout
// (maybe to the entire coroutine) using asio::cancel_after
mysql::pooled_connection conn = co_await pool.async_get_connection();
// Use it normally
mysql::results result;
co_await conn->async_execute("SELECT...", result);
// conn's destructor returns it to the pool
} Hope it helps. |
I am using boost 1.86 and seeing a random assert failure at times. the same query works fine but asserts at times. wondering what is the cause for below assert failure,
/work/opensource//base/boost_1_86_0/boost/mysql/impl/internal/sansio/read_buffer.hpp:90: void boost::mysql::detail::read_buffer::move_to_pending(std::size_t): Assertion `length <= free_size()' failed.
.
The text was updated successfully, but these errors were encountered: