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

P2P: Misc improvements #1040

Merged
merged 5 commits into from
Apr 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions plugins/net_plugin/net_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ namespace eosio {
alignas(hardware_destructive_interference_size)
std::atomic<bool> connecting{true};
std::atomic<bool> syncing{false};
std::atomic<bool> closing{false};

std::atomic<uint16_t> protocol_version = 0;
uint16_t net_version = net_version_max;
Expand Down Expand Up @@ -1030,7 +1031,7 @@ namespace eosio {
}

bool connection::connected() const {
return socket_is_open() && !connecting;
return socket_is_open() && !connecting && !closing;
}

bool connection::current() const {
Expand All @@ -1042,6 +1043,7 @@ namespace eosio {
}

void connection::close( bool reconnect, bool shutdown ) {
closing = true;
strand.post( [self = shared_from_this(), reconnect, shutdown]() {
connection::_close( self.get(), reconnect, shutdown );
});
Expand All @@ -1059,6 +1061,7 @@ namespace eosio {
self->flush_queues();
self->connecting = false;
self->syncing = false;
self->closing = false;
self->block_status_monitor_.reset();
++self->consecutive_immediate_connection_close;
bool has_last_req = false;
Expand Down Expand Up @@ -1175,6 +1178,8 @@ namespace eosio {
}

void connection::send_handshake() {
if (closing)
return;
strand.post( [c = shared_from_this()]() {
std::unique_lock<std::mutex> g_conn( c->conn_mtx );
if( c->populate_handshake( c->last_handshake_sent ) ) {
Expand Down Expand Up @@ -1250,7 +1255,7 @@ namespace eosio {

// called from connection strand
void connection::do_queue_write() {
if( !buffer_queue.ready_to_send() )
if( !buffer_queue.ready_to_send() || closing )
return;
connection_ptr c(shared_from_this());

Expand Down Expand Up @@ -2373,8 +2378,7 @@ namespace eosio {
c->send_handshake();
}
} else {
fc_elog( logger, "connection failed to ${host}:${port} ${error}",
("host", endpoint.address().to_string())("port", endpoint.port())( "error", err.message()));
fc_elog( logger, "connection failed to ${a}, ${error}", ("a", c->peer_address())( "error", err.message()));
c->close( false );
}
} ) );
Expand Down