mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3416 from yichengq/get-cluster-timeout
etcdserver: add timeout param on getClusterFromRemotePeers
This commit is contained in:
commit
8ac981e1ee
@ -30,7 +30,7 @@ import (
|
|||||||
// isMemberBootstrapped tries to check if the given member has been bootstrapped
|
// isMemberBootstrapped tries to check if the given member has been bootstrapped
|
||||||
// in the given cluster.
|
// in the given cluster.
|
||||||
func isMemberBootstrapped(cl *cluster, member string, tr *http.Transport) bool {
|
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 {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -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
|
// 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
|
// a response, or a Cluster cannot be successfully created from a received
|
||||||
// response, an error is returned.
|
// 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) {
|
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.
|
// 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{
|
cc := &http.Client{
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
Timeout: time.Second,
|
Timeout: timeout,
|
||||||
}
|
}
|
||||||
for _, u := range urls {
|
for _, u := range urls {
|
||||||
resp, err := cc.Get(u + "/members")
|
resp, err := cc.Get(u + "/members")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user