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

server: cleanup persistent connection retries #982

Merged
merged 11 commits into from
Mar 31, 2018

Conversation

cfromknecht
Copy link
Contributor

@cfromknecht cfromknecht commented Mar 30, 2018

Complementary to #981.

This commits changes the behavior of our connection
reestablishment, and resolves some minor issues that
could lead to uncancelled requests or an infinite
connection loop.

  • Will not attempt to Remove connection requests with
    an ID of 0. This can happen for reconnect attempts
    that get scheduled, but have not started at the
    time the server cancels the connection requests.

  • Adds a per-peer cancellation channel, that is
    closed upon a successful inbound or outbound
    connection. The goroutine spwaned to handle the
    reconnect by the peerTerminationWatch now
    selects on this channel, and skips reconnecting
    if it is closed before the backoff matures.

  • Properly computes the backoff when no entry in
    persistentPeersBackoff is found. Previously, a
    value of 0 would be returned, cause all subsequent
    backoff attempts to use a backoff of 0.

  • Cancels a peer's retries and remove connections
    immediately after receiving an inbound connection,
    to mimic the structure of OutboundPeerConnected.

Fixes #935, #941, #979, #982.

…fallback to default port

In this commit, we fix an existing bug within the codebase: if a peer
connected to us inbound, then we'd attempt to use the assigned port when
re-establishing a connection to them. We fix this issue in this commit
by adding a new method to look up any advertisements for the peer, and
use the specified port that matches our connection attempt. If we can't
find a proper advertisement, then we'll simply use the default peer
port.
@meshcollider meshcollider added the p2p Code related to the peer-to-peer behaviour label Mar 31, 2018
aakselrod
aakselrod previously approved these changes Mar 31, 2018
Copy link
Contributor

@aakselrod aakselrod left a comment

Choose a reason for hiding this comment

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

These changes look good to me.

In this commit, we fix a minor bug in the prior versions of lnd. Before
this commit, if we received a new inbound connection for channel
creation, the channel was created, and then the peer disconnected, we
wouldn't automatically reconnect.

In this commit we fix this issue by overloading the WatchNewChannel
method to also accept the peer's ID so we can add it to the set of
persistent connections.
lnd.go Outdated
addr *lnwire.NetAddress) error {

// First, we'll mark this new peer as a persistent
// re-connection purposes.
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) comment typo "... as a persistent [peer for] re-connection purposes."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks!

@cfromknecht cfromknecht force-pushed the server-conns branch 2 times, most recently from dba8c5a to d0a4231 Compare March 31, 2018 07:48
This commits changes the behavior of our connection
reestablishment, and resolves some minor issues that
could lead to uncancelled requests or an infinite
connection loop.

 - Will not attempt to Remove connection requests with
   an ID of 0. This can happen for reconnect attempts
   that get scheduled, but have not started at the
   time the server cancels the connection requests.

 - Adds a per-peer cancellation channel, that is
   closed upon a successful inbound or outbound
   connection. The goroutine spwaned to handle the
   reconnect by the peerTerminationWatch now
   selects on this channel, and skips reconnecting
   if it is closed before the backoff matures.

 - Properly computes the backoff when no entry in
   persistentPeersBackoff is found. Previously, a
   value of 0 would be returned, cause all subsequent
   backoff attempts to use a backoff of 0.

 - Cancels a peers retries and remove connections
   immediately after receiving an inbound connection,
   to mimic the structure of OutboundPeerConnected.

 - Cancels all persistent connection requests after
   calling DisconnectPeers.

 - Allow additional connection attempts to peers, even if
   there already exists a pending connection attempt.
Alters the behavior of ConnectEnsure to initiate a connection
attempt in both directions. Additionally, the wait predicate only
returns true after cross checking both peer lists.
@cfromknecht cfromknecht force-pushed the server-conns branch 2 times, most recently from 6a5f46b to c8323a4 Compare March 31, 2018 08:38
Uses EnsureConnected when reconnecting nodes in:
 - switch offline delivery persistence
 - graph topology notifications
 - channel funding persistence
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2p Code related to the peer-to-peer behaviour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Channel peer reconnection
5 participants