Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Revert "wait for 2 seconds on disconnect" changes (#5841)
Browse files Browse the repository at this point in the history
Revert "wait for 2 seconds on disconnect" changes
  • Loading branch information
gumb0 committed Nov 22, 2019
2 parents 96ad1b9 + d745f4f commit dfb76ed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [1.7.2] - Unreleased

- Fixed: [#5834](https://github.com/ethereum/aleth/pull/5834) Fix segmentation fault during sync.
- Fixed: [#5841](https://github.com/ethereum/aleth/pull/5841) Revert the change introduced in 1.7.0 to wait 2 secods after sending `Disconnect` to peer before closing the socket, as it caused instabilty during sync.

## [1.7.1] - 2019-11-18

Expand Down
8 changes: 0 additions & 8 deletions libp2p/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,3 @@ void Host::forEachPeer(
return;
}

std::unique_ptr<ba::steady_timer> Host::createTimer(std::chrono::seconds const& _expiryDelay,
std::function<void(const boost::system::error_code& error)>&& _f)
{
std::unique_ptr<ba::steady_timer> timer{new ba::steady_timer{m_ioContext}};
timer->expires_after(_expiryDelay);
timer->async_wait(_f);
return timer;
}
5 changes: 0 additions & 5 deletions libp2p/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,6 @@ class Host: public Worker

std::shared_ptr<CapabilityHostFace> capabilityHost() const { return m_capabilityHost; }

/// Execute work on the network thread after an @a _expiryDelay delay.
/// Returned timer should be kept alive until delay is over.
std::unique_ptr<ba::steady_timer> createTimer(std::chrono::seconds const& _expiryDelay,
std::function<void(const boost::system::error_code& error)>&& _f);

protected:
/*
* Used by the host to run a capability's background work loop
Expand Down
33 changes: 16 additions & 17 deletions libp2p/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ bool Session::checkPacket(bytesConstRef _msg)

void Session::send(bytes&& _msg)
{
if (m_dropped)
return;

bytesConstRef msg(&_msg);
LOG(m_netLoggerDetail) << capabilityPacketTypeToString(_msg[0]) << " to";
if (!checkPacket(msg))
Expand Down Expand Up @@ -279,6 +276,16 @@ void Session::drop(DisconnectReason _reason)
{
if (m_dropped)
return;
bi::tcp::socket& socket = m_socket->ref();
if (socket.is_open())
try
{
boost::system::error_code ec;
LOG(m_netLoggerDetail) << "Closing (" << reasonOf(_reason) << ") connection with";
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
socket.close();
}
catch (...) {}

m_peer->m_lastDisconnect = _reason;
if (_reason == BadProtocol)
Expand All @@ -291,22 +298,14 @@ void Session::drop(DisconnectReason _reason)

void Session::disconnect(DisconnectReason _reason)
{
if (m_dropped)
return;

clog(VerbosityTrace, "p2pcap") << "Disconnecting (our reason: " << reasonOf(_reason) << ") from " << m_logSuffix;

RLPStream s;
prep(s, DisconnectPacket, 1) << (int)_reason;
sealAndSend(s);

auto self(shared_from_this());
// The empty handler will keep the Session alive for the supplied amount of time, after
// which Host will garbage-collect the Session which will invoke the Session dtor and close the
// socket
m_disconnectTimer =
m_server->createTimer(std::chrono::seconds(2), [self](boost::system::error_code) {});

if (m_socket->ref().is_open())
{
RLPStream s;
prep(s, DisconnectPacket, 1) << (int)_reason;
sealAndSend(s);
}
drop(_reason);
}

Expand Down
4 changes: 1 addition & 3 deletions libp2p/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Session: public SessionFace, public std::enable_shared_from_this<SessionFa

void ping() override;

bool isConnected() const override { return !m_dropped; }
bool isConnected() const override { return m_socket->ref().is_open(); }

NodeID id() const override;

Expand Down Expand Up @@ -177,8 +177,6 @@ class Session: public SessionFace, public std::enable_shared_from_this<SessionFa

std::set<std::string> m_disabledCapabilities;

std::unique_ptr<ba::steady_timer> m_disconnectTimer;

std::string m_logSuffix;

Logger m_netLogger{createLogger(VerbosityDebug, "net")};
Expand Down

0 comments on commit dfb76ed

Please sign in to comment.