Skip to content
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

Feature/reentrancy #111

Merged
merged 96 commits into from Apr 2, 2021
Merged

Feature/reentrancy #111

merged 96 commits into from Apr 2, 2021

Conversation

art-gor
Copy link
Contributor

@art-gor art-gor commented Feb 11, 2021

This update resolves the following:

  1. No more throws from boost calls;
  2. Async operations are not reentrant (callback passed in arguments is guaranteed not to be called from withing the function);
  3. Yamux redesigned, resolved window issues, data losses, delays due to window management;

art-gor and others added 30 commits September 30, 2020 12:40
Signed-off-by: Igor Egorov <igor@soramitsu.co.jp>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
refactoring: replace deprecated sha256 function by hasher

Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
@igor-egorov
Copy link
Member

Address sanitizer reports a heap-use-after-free error when launching rendezvous_chat at the last commit 5545319. This started to happen only within that pr.

Please check the log attached. Please fix the memory corruption.

asan-3.txt
(the log was collected on Ubuntu 18.04, clang-11.1.0)

@art-gor art-gor marked this pull request as ready for review March 12, 2021 06:08
Copy link
Member

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first phase of review done.

Copy link
Member

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

include/libp2p/basic/reader.hpp Outdated Show resolved Hide resolved
*
* @note if (!ec) then this function does nothing
*/
virtual void deferReadCallback(outcome::result<size_t> res,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Callback aleady has an argument of type outcome::result<size_t> - was it expected the first argument to be an error_code like in deferWriteCallback?

  2. If 1 is true, then can we have a single method named something like deferIoCallback?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. fixed
  2. trying to avoid diamond hierarchy

*
* @note if (!ec) then this function does nothing
*/
virtual void deferWriteCallback(std::error_code ec, WriteCallbackFunc cb) = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to pass ec into that method? Can we just do the check outside of that method implementation if needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we can, but the fn will do nothing anyways

include/libp2p/basic/reader.hpp Outdated Show resolved Hide resolved
src/basic/varint_reader.cpp Outdated Show resolved Hide resolved
@@ -131,438 +147,535 @@ namespace libp2p::connection {

void YamuxedConnection::read(gsl::span<uint8_t> out, size_t bytes,
ReadCallbackFunc cb) {
connection_->read(out, bytes, std::move(cb));
log()->critical("YamuxedConnection::read : invalid direct call");
deferReadCallback(YamuxError::FORBIDDEN_CALL, std::move(cb));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed offline - this could be the reason the multiselect protocol gets broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that it's not where it breaks, unfortunately

void YamuxedConnection::writeStreamData(uint32_t stream_id,
gsl::span<const uint8_t> data,
bool some) {
// TODO(artem): reform in buffers (shared + vector writes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix or create an issue with a clear description. Unfortunately, it does not prescriptive enough of what to do.

include/libp2p/transport/tcp/tcp_connection.hpp Outdated Show resolved Hide resolved
src/protocol/echo/server_echo_session.cpp Outdated Show resolved Hide resolved
include/libp2p/basic/reader.hpp Outdated Show resolved Hide resolved

capacity_remains_ = alloc_granularity_;
} else {
fragments_.emplace_back();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok if new fragment will be added only for oversized data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, some heuristic here to minimize copying


capacity_remains_ -= sz;
} else if (capacity_remains_ > 0) {
auto &vec = fragments_.back();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok if parts of data which size less remaining capacity will inflate only one fragment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, only last fragmen's capacity counts

total_size_ = 0;
first_byte_offset_ = 0;
capacity_remains_ = 0;
std::deque<Fragment>{}.swap(fragments_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is advantages to use swap instead clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deallocation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it will be deallocated anyway in dtor at out of scope

src/basic/read_buffer.cpp Show resolved Hide resolved
test/libp2p/muxer/muxers_and_streams_test.cpp Outdated Show resolved Hide resolved
test/libp2p/muxer/muxers_and_streams_test.cpp Outdated Show resolved Hide resolved
test/libp2p/muxer/muxers_and_streams_test.cpp Outdated Show resolved Hide resolved
@@ -66,16 +71,16 @@ TEST(EchoTest, Server) {
* @when client writes string "hello" to the Stream
* @then client reads back the same string
*/
TEST(EchoTest, Client) {
TEST(EchoTest, DISABLED_Client) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment, please, why is it disabled and issue (number or link) to enable it back.
Or remove if it really needless anymore

Copy link
Contributor Author

@art-gor art-gor Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test expects reentrant behavior from mocks and other objects, needs to be rewritten as soon as new testing tools for async appears (net PR)

src/muxer/yamux/yamuxed_connection.cpp Outdated Show resolved Hide resolved
@igor-egorov igor-egorov requested a review from xDimon March 24, 2021 14:42
* multiselect revised, WIP

* multiselect: simple outbound stream negotiate

* multiselect numerous fixes

* multiselect: instances and reuse

* multiselect: fixes

* multiselect: removed old implementation

* multiselect: interop with go impl fixes

* multiselect: bugfixes

* multiselect: ProtocolMuxer interface abstracts simple outbound stream negotiation

* multiselect: cleanups and logging

* trigger CI

* temporarily disabled tests that required synchronous reaction of multiselect

* just removed unused lines

* reverted back ci.yml
@art-gor art-gor merged commit 8d1b7ef into master Apr 2, 2021
@art-gor art-gor deleted the feature/reentrancy branch April 2, 2021 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants