Skip to content

Commit

Permalink
etcdserver: add timeout param on getClusterFromRemotePeers
Browse files Browse the repository at this point in the history
It sets 10s timeout for public GetClusterFromRemotePeers.

This helps the following cases to work well in high latency scenario:

1. proxy sync members from the cluster
2. newly-joined member sync members from the cluster

Besides 10s request timeout, the request is also controlled by dial
timeout and read connection timeout.
  • Loading branch information
yichengq committed Sep 1, 2015
1 parent 57b39ac commit f3bfcb9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions etcdserver/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// isMemberBootstrapped tries to check if the given member has been bootstrapped
// in the given cluster.
func isMemberBootstrapped(cl *cluster, member string, tr *http.Transport) bool {
rcl, err := getClusterFromRemotePeers(getRemotePeerURLs(cl, member), false, tr)
rcl, err := getClusterFromRemotePeers(getRemotePeerURLs(cl, member), time.Second, false, tr)
if err != nil {
return false
}
Expand All @@ -50,15 +50,17 @@ func isMemberBootstrapped(cl *cluster, member string, tr *http.Transport) bool {
// these URLs. The first URL to provide a response is used. If no URLs provide
// a response, or a Cluster cannot be successfully created from a received
// response, an error is returned.
// Each request has a 10-second timeout. Because the upper limit of TTL is 5s,
// 10 second is enough for building connection and finishing request.
func GetClusterFromRemotePeers(urls []string, tr *http.Transport) (*cluster, error) {
return getClusterFromRemotePeers(urls, true, tr)
return getClusterFromRemotePeers(urls, 10*time.Second, true, tr)
}

// If logerr is true, it prints out more error messages.
func getClusterFromRemotePeers(urls []string, logerr bool, tr *http.Transport) (*cluster, error) {
func getClusterFromRemotePeers(urls []string, timeout time.Duration, logerr bool, tr *http.Transport) (*cluster, error) {
cc := &http.Client{
Transport: tr,
Timeout: time.Second,
Timeout: timeout,
}
for _, u := range urls {
resp, err := cc.Get(u + "/members")
Expand Down

0 comments on commit f3bfcb9

Please sign in to comment.