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]: Start Peers Asynchronously #1658

Merged
merged 4 commits into from Aug 16, 2018

Commits on Aug 14, 2018

  1. peer: add ready chan arg to WaitForDisconnect

    This commit adds additional synchronization logic to
    WaitForDisconnect, such that it can be spawned before
    Start has been executed by the server. Without
    modification, the current version will return
    immediately since no goroutines will have been
    spawned.
    
    To solve this, we modify WaitForDisconnect to block until:
     1) the peer is disconnected,
     2) the peer is successfully started,
    before watching the waitgroup.
    
    In the first case, the waitgroup will block until all
    (if any) spawned goroutines have exited. Otherwise, if
    the Start is successful, we can switch to watching the
    waitgroup, knowing that waitgroup counter is positive.
    cfromknecht committed Aug 14, 2018
    Copy the full SHA
    a1abb11 View commit details
    Browse the repository at this point in the history
  2. server: add async peer Start() + safer cleanup

    This commit adds asynchronous starting of peers,
    in order to avoid potential DOS vectors. Currently,
    we block with the server's mutex while peers exchange
    Init messages and perform other setup. Thus, a remote
    peer that does not reply with an init message will
    cause server to block for 15s per attempt.
    
    We also modify the startup behavior to spawn
    peerTerminationWatchers before starting the
    peer itself, ensuring that a peer is properly
    cleaned up if the initialization fails. Currently,
    failing to start a peer does not execute the bulk
    of the teardown logic, since it is not spawned
    until after a successful Start occurs.
    cfromknecht committed Aug 14, 2018
    Copy the full SHA
    0ee0abc View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    1212529 View commit details
    Browse the repository at this point in the history
  4. peer: increase peer write timeout to 50 seconds

    Sometimes when performing an initial sync, the remote
    node isn't able to pull messages off the wire because
    of long running tasks and queues are saturated. With
    a shorter write timeout, we will give up trying to send
    messages and teardown the connection, even though the
    peer is still active.
    cfromknecht committed Aug 14, 2018
    Copy the full SHA
    d4d9097 View commit details
    Browse the repository at this point in the history