From fc02b0c6ed24375de80ca5f4a5e9d965bbfe5c2d Mon Sep 17 00:00:00 2001 From: Igor Egorov Date: Sat, 1 Feb 2025 01:12:29 +0300 Subject: [PATCH 1/5] closeOnError: call cb() before close() Signed-off-by: Igor Egorov --- src/security/tls/tls_connection.cpp | 3 ++- src/transport/tcp/tcp_connection.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/security/tls/tls_connection.cpp b/src/security/tls/tls_connection.cpp index 7bdb15c8..5d4b54a5 100644 --- a/src/security/tls/tls_connection.cpp +++ b/src/security/tls/tls_connection.cpp @@ -132,8 +132,9 @@ namespace libp2p::connection { auto &&result) { if (ec) { SL_DEBUG(log(), "connection async op error {}", ec); + cb(ec); std::ignore = conn->close(); - return cb(ec); + return; } cb(std::forward(result)); }; diff --git a/src/transport/tcp/tcp_connection.cpp b/src/transport/tcp/tcp_connection.cpp index 6aa317de..dab82387 100644 --- a/src/transport/tcp/tcp_connection.cpp +++ b/src/transport/tcp/tcp_connection.cpp @@ -95,8 +95,9 @@ namespace libp2p::transport { auto result) { if (auto self = wptr.lock()) { if (ec) { + cb(ec); self->close(ec); - return cb(ec); + return; } TRACE("{} {}", self->str(), result); cb(result); From e171915acf19121bff668cf7904b14bf5c8eb55b Mon Sep 17 00:00:00 2001 From: Igor Egorov Date: Wed, 5 Feb 2025 17:06:07 +0300 Subject: [PATCH 2/5] Countable yamux and yamux read buffer --- include/libp2p/muxer/yamux/yamuxed_connection.hpp | 9 ++++++++- src/muxer/yamux/yamuxed_connection.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/libp2p/muxer/yamux/yamuxed_connection.hpp b/include/libp2p/muxer/yamux/yamuxed_connection.hpp index 6ac7dd59..f2e5f6cf 100644 --- a/include/libp2p/muxer/yamux/yamuxed_connection.hpp +++ b/include/libp2p/muxer/yamux/yamuxed_connection.hpp @@ -18,6 +18,13 @@ namespace libp2p::connection { + class CountableBuffer : public std::vector { + public: + LIBP2P_METRICS_INSTANCE_COUNT_IF_ENABLED( + libp2p::connection::CountableBuffer); + }; + + /** * Implementation of stream multiplexer - connection, which has only one * physical link to another peer, but many logical streams, for example, for @@ -193,7 +200,7 @@ namespace libp2p::connection { bool started_ = false; /// TODO(artem): change read() interface to reduce copying - std::shared_ptr raw_read_buffer_; + std::shared_ptr raw_read_buffer_; /// Buffering and segmenting YamuxReadingState reading_state_; diff --git a/src/muxer/yamux/yamuxed_connection.cpp b/src/muxer/yamux/yamuxed_connection.cpp index ffe7dbab..6d62af02 100644 --- a/src/muxer/yamux/yamuxed_connection.cpp +++ b/src/muxer/yamux/yamuxed_connection.cpp @@ -37,7 +37,7 @@ namespace libp2p::connection { : config_(config), connection_(std::move(connection)), scheduler_(std::move(scheduler)), - raw_read_buffer_(std::make_shared()), + raw_read_buffer_(std::make_shared()), reading_state_( [this](boost::optional header) { return processHeader(std::move(header)); From 88cdeeda9554be05ff4aef6546fc3e716fc36001 Mon Sep 17 00:00:00 2001 From: Igor Egorov Date: Wed, 5 Feb 2025 17:49:24 +0300 Subject: [PATCH 3/5] Count yamux metrics forcefully --- include/libp2p/muxer/yamux/yamuxed_connection.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libp2p/muxer/yamux/yamuxed_connection.hpp b/include/libp2p/muxer/yamux/yamuxed_connection.hpp index f2e5f6cf..61d7ec2e 100644 --- a/include/libp2p/muxer/yamux/yamuxed_connection.hpp +++ b/include/libp2p/muxer/yamux/yamuxed_connection.hpp @@ -20,7 +20,7 @@ namespace libp2p::connection { class CountableBuffer : public std::vector { public: - LIBP2P_METRICS_INSTANCE_COUNT_IF_ENABLED( + LIBP2P_METRICS_INSTANCE_COUNT( libp2p::connection::CountableBuffer); }; @@ -249,7 +249,7 @@ namespace libp2p::connection { bool close_after_write_ = false; public: - LIBP2P_METRICS_INSTANCE_COUNT_IF_ENABLED( + LIBP2P_METRICS_INSTANCE_COUNT( libp2p::connection::YamuxedConnection); }; From 046281f5d1eed703d5780e4ab6827cfa6a756e6d Mon Sep 17 00:00:00 2001 From: Igor Egorov Date: Wed, 12 Feb 2025 11:37:11 +0300 Subject: [PATCH 4/5] Revert "Count yamux metrics forcefully" This reverts commit 88cdeeda9554be05ff4aef6546fc3e716fc36001. --- include/libp2p/muxer/yamux/yamuxed_connection.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libp2p/muxer/yamux/yamuxed_connection.hpp b/include/libp2p/muxer/yamux/yamuxed_connection.hpp index 61d7ec2e..f2e5f6cf 100644 --- a/include/libp2p/muxer/yamux/yamuxed_connection.hpp +++ b/include/libp2p/muxer/yamux/yamuxed_connection.hpp @@ -20,7 +20,7 @@ namespace libp2p::connection { class CountableBuffer : public std::vector { public: - LIBP2P_METRICS_INSTANCE_COUNT( + LIBP2P_METRICS_INSTANCE_COUNT_IF_ENABLED( libp2p::connection::CountableBuffer); }; @@ -249,7 +249,7 @@ namespace libp2p::connection { bool close_after_write_ = false; public: - LIBP2P_METRICS_INSTANCE_COUNT( + LIBP2P_METRICS_INSTANCE_COUNT_IF_ENABLED( libp2p::connection::YamuxedConnection); }; From 3dadf6f8a9fea3da74928f30cafb331216c56fbe Mon Sep 17 00:00:00 2001 From: Igor Egorov Date: Wed, 12 Feb 2025 11:37:24 +0300 Subject: [PATCH 5/5] Revert "Countable yamux and yamux read buffer" This reverts commit e171915acf19121bff668cf7904b14bf5c8eb55b. --- include/libp2p/muxer/yamux/yamuxed_connection.hpp | 9 +-------- src/muxer/yamux/yamuxed_connection.cpp | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/include/libp2p/muxer/yamux/yamuxed_connection.hpp b/include/libp2p/muxer/yamux/yamuxed_connection.hpp index f2e5f6cf..6ac7dd59 100644 --- a/include/libp2p/muxer/yamux/yamuxed_connection.hpp +++ b/include/libp2p/muxer/yamux/yamuxed_connection.hpp @@ -18,13 +18,6 @@ namespace libp2p::connection { - class CountableBuffer : public std::vector { - public: - LIBP2P_METRICS_INSTANCE_COUNT_IF_ENABLED( - libp2p::connection::CountableBuffer); - }; - - /** * Implementation of stream multiplexer - connection, which has only one * physical link to another peer, but many logical streams, for example, for @@ -200,7 +193,7 @@ namespace libp2p::connection { bool started_ = false; /// TODO(artem): change read() interface to reduce copying - std::shared_ptr raw_read_buffer_; + std::shared_ptr raw_read_buffer_; /// Buffering and segmenting YamuxReadingState reading_state_; diff --git a/src/muxer/yamux/yamuxed_connection.cpp b/src/muxer/yamux/yamuxed_connection.cpp index 6d62af02..ffe7dbab 100644 --- a/src/muxer/yamux/yamuxed_connection.cpp +++ b/src/muxer/yamux/yamuxed_connection.cpp @@ -37,7 +37,7 @@ namespace libp2p::connection { : config_(config), connection_(std::move(connection)), scheduler_(std::move(scheduler)), - raw_read_buffer_(std::make_shared()), + raw_read_buffer_(std::make_shared()), reading_state_( [this](boost::optional header) { return processHeader(std::move(header));