Skip to content

Commit

Permalink
GOCBC-102: Ensure config is validated for HTTP bootstrap.
Browse files Browse the repository at this point in the history
Previously, config's received via HTTP bootstrapping were not
properly validated before being activated as the client's
initial configuration.  This caused newly created buckets with
no vbuckets to be activated and subsequently crash the client.

Change-Id: I25a3c7e8959ed4ed0b91d322e7939faecf128d26
Reviewed-on: http://review.couchbase.org/62569
Reviewed-by: Mark Nunberg <mark.nunberg@couchbase.com>
Tested-by: Brett Lawson <brett19@gmail.com>
  • Loading branch information
brett19 committed Apr 7, 2016
1 parent 6e4c777 commit 998b212
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
21 changes: 16 additions & 5 deletions gocbcore/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,31 @@ func (c *Agent) connect(memdAddrs, httpAddrs []string, deadline time.Time) error
mgmtEpList: epList,
})

var bk *cfgBucket
var routeCfg *routeConfig

logDebugf("Starting HTTP looper! %v", epList)
go c.httpLooper(func(cfg *cfgBucket, err error) {
bk = cfg
signal <- err
go c.httpLooper(func(cfg *cfgBucket, err error) bool {
if err != nil {
signal <- err
return true
}

newRouteCfg := buildRouteConfig(cfg, c.IsSecure())
if !newRouteCfg.IsValid() {
// Something is invalid about this config, keep trying
return false
}

routeCfg = newRouteCfg
signal <- nil
return true
})

err := <-signal
if err != nil {
return err
}

routeCfg := buildRouteConfig(bk, c.IsSecure())
c.numVbuckets = len(routeCfg.vbMap)
c.applyConfig(routeCfg)

Expand Down
8 changes: 6 additions & 2 deletions gocbcore/agenthttpcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func hostnameFromUri(uri string) string {
return strings.Split(uriInfo.Host, ":")[0]
}

func (c *Agent) httpLooper(firstCfgFn func(*cfgBucket, error)) {
func (c *Agent) httpLooper(firstCfgFn func(*cfgBucket, error) bool) {
waitPeriod := 20 * time.Second
maxConnPeriod := 10 * time.Second
var iterNum uint64 = 1
Expand Down Expand Up @@ -161,7 +161,11 @@ func (c *Agent) httpLooper(firstCfgFn func(*cfgBucket, error)) {
iterSawConfig = true
if isFirstTry {
logDebugf("HTTP Config Init")
firstCfgFn(bkCfg, nil)
if !firstCfgFn(bkCfg, nil) {
logDebugf("Got error while activating first config")
resp.Body.Close()
break
}
isFirstTry = false
} else {
logDebugf("HTTP Config Update")
Expand Down

0 comments on commit 998b212

Please sign in to comment.