Browse Source

bump to use latest go-etcd

Picks up changes to better handle etcd watch timesouts.

Fixes #27
Eugene Yakubovich 10 years ago
parent
commit
ad26b42144
2 changed files with 33 additions and 14 deletions
  1. 2 2
      Godeps/Godeps.json
  2. 31 12
      Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/requests.go

+ 2 - 2
Godeps/Godeps.json

@@ -7,8 +7,8 @@
 	"Deps": [
 		{
 			"ImportPath": "github.com/coreos/go-etcd/etcd",
-			"Comment": "v0.2.0-rc1-120-g23142f6",
-			"Rev": "23142f6773a676cc2cae8dd0cb90b2ea761c853f"
+			"Comment": "v0.2.0-rc1-123-g0157fac",
+			"Rev": "0157fac4bb9567e843bdbb5854e966862c36be09"
 		},
 		{
 			"ImportPath": "github.com/coreos/go-systemd/daemon",

+ 31 - 12
Godeps/_workspace/src/github.com/coreos/go-etcd/etcd/requests.go

@@ -3,6 +3,7 @@ package etcd
 import (
 	"errors"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"math/rand"
 	"net/http"
@@ -179,6 +180,7 @@ func (c *Client) SendRequest(rr *RawRequest) (*RawResponse, error) {
 	// we connect to a leader
 	sleep := 25 * time.Millisecond
 	maxSleep := time.Second
+
 	for attempt := 0; ; attempt++ {
 		if attempt > 0 {
 			select {
@@ -214,21 +216,29 @@ func (c *Client) SendRequest(rr *RawRequest) (*RawResponse, error) {
 
 		logger.Debug("send.request.to ", httpPath, " | method ", rr.Method)
 
-		reqLock.Lock()
-		if rr.Values == nil {
-			if req, err = http.NewRequest(rr.Method, httpPath, nil); err != nil {
-				return nil, err
-			}
-		} else {
-			body := strings.NewReader(rr.Values.Encode())
-			if req, err = http.NewRequest(rr.Method, httpPath, body); err != nil {
-				return nil, err
+		req, err := func() (*http.Request, error) {
+			reqLock.Lock()
+			defer reqLock.Unlock()
+
+			if rr.Values == nil {
+				if req, err = http.NewRequest(rr.Method, httpPath, nil); err != nil {
+					return nil, err
+				}
+			} else {
+				body := strings.NewReader(rr.Values.Encode())
+				if req, err = http.NewRequest(rr.Method, httpPath, body); err != nil {
+					return nil, err
+				}
+
+				req.Header.Set("Content-Type",
+					"application/x-www-form-urlencoded; param=value")
 			}
+			return req, nil
+		}()
 
-			req.Header.Set("Content-Type",
-				"application/x-www-form-urlencoded; param=value")
+		if err != nil {
+			return nil, err
 		}
-		reqLock.Unlock()
 
 		resp, err = c.httpClient.Do(req)
 		defer func() {
@@ -274,6 +284,15 @@ func (c *Client) SendRequest(rr *RawRequest) (*RawResponse, error) {
 				return nil, ErrRequestCancelled
 			default:
 			}
+
+			if err == io.ErrUnexpectedEOF {
+				// underlying connection was closed prematurely, probably by timeout
+				// TODO: empty body or unexpectedEOF can cause http.Transport to get hosed;
+				// this allows the client to detect that and take evasive action. Need
+				// to revisit once code.google.com/p/go/issues/detail?id=8648 gets fixed.
+				respBody = []byte{}
+				break
+			}
 		}
 
 		// if resp is TemporaryRedirect, set the new leader and retry