diff --git a/dstore/host.go b/dstore/host.go index 5ca468b..7648842 100644 --- a/dstore/host.go +++ b/dstore/host.go @@ -169,11 +169,14 @@ func (host *Host) executeWithTimeout(req *mc.Request, timeout time.Duration) (re } }() + timer := time.NewTimer(timeout) + defer timer.Stop() + select { case <-done: resp = tmpResp err = tmpErr - case <-time.After(timeout): + case <-timer.C: isTimeout <- true err = fmt.Errorf("request %v timeout", req) logger.Infof("request %v to host %s timeout", req, host.Addr) diff --git a/go.mod b/go.mod index b22b547..a74df06 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/douban/gobeansproxy require ( github.com/davecgh/go-spew v1.1.0 // indirect - github.com/douban/gobeansdb v1.1.0 + github.com/douban/gobeansdb v1.1.2 github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 gopkg.in/yaml.v2 v2.2.1 diff --git a/go.sum b/go.sum index 89bf573..5446512 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/douban/gobeansdb v1.1.0 h1:Ia659+3inop0LFeS8/aLFM7mEcJ0hdX0fcIGrZC1aDw= -github.com/douban/gobeansdb v1.1.0/go.mod h1:1Irour4eUljC+P/4aD6qI1z9zWao4IzQYJmfuRqcH7o= +github.com/douban/gobeansdb v1.1.2 h1:3PbCOWFheciPWc3dgRJF+uUfsorF6RgMN7y4TmyX3Fk= +github.com/douban/gobeansdb v1.1.2/go.mod h1:lSxWZJgFFUTy4WzcXTVn0g1hvEMwW3InXAUeZngsvMk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec h1:6ncX5ko6B9LntYM0YBRXkiSaZMmLYeZ/NWcmeB43mMY= @@ -9,6 +9,13 @@ github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec/go.mod h1:gi+0 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20191011211836-4c025a95b26e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=