Wrap boost::asio::async_write to ensure lifetime of buffers #2240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduce a new class
nano::shared_const_buffer
which @cryptocode found an example for here: https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio/example/cpp11/buffers/reference_counted.cpp This should alleviate any buffer memory not being captured or having sufficient lifetime during theboost::asio::async_write
call. When building travis I check ifboost::asio::async_write
is called anywhere other than the new file which wraps itnano/lib/asio.hpp
and error out with a message if it is.I think any minor performance hits we have by always using a
shared_ptr
are outweighed by keeping the program correct, as this has bitten us in the past and I found yet more places (nano::rpc_request_processor::try_reconnect_and_execute_request) where this wasn't done properly even though we actively try make sure it is.