-
Notifications
You must be signed in to change notification settings - Fork 642
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
read Operation canceled and read partial message for 2 continuous http::async_write() #1912
Comments
This code has a data race. You're seeing undefined behaviour because of that. |
thanks @madmongo1 I will have only 1 thread calling the |
You have a race because you're not co-ordinating the beginning of the first asynchronous sequence (send, receive) with the end of the last one. You are not allowed to have more than one asynchronous write and one asyncronous read in progress at any time on any stream in asio. If you are going to split this code into 2 threads , you must enqueue the second request until the first is complete. |
@madmongo1 I updated the code and only enqueueing
|
A
You can adapt this to HTTP messages instead. |
@vinniefalco thanks a lot Vinnie, you are the superhero! This pattern worked, I got
|
much better |
BOOST_BEAST_VERSION 255
Basically I composed this http_client_async_ssl sample and Vinnie's sample code with queue
But when I tried to send 2 requests, both of them failed like this:
When I sent only 1 request, it succeeded.
When I tried to
sleep(2)
for 2 seconds between the 2 requests, both succeeded.Not sure if it is because the type I defined
using tcp_stream_tp = beast::basic_stream<net::ip::tcp, net::strand<net::io_context::executor_type>, beast::unlimited_rate_policy>
?Http code:
Code which sends the requests:
The text was updated successfully, but these errors were encountered: