lock: slice length of lock clients should be precisely urls. (#3254)

This patch fixes a possible bug, reproduced rarely only seen
once.

```
panic: runtime error: index out of range

goroutine 136 [running]:
panic(0xac1a40, 0xc4200120b0)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/minio/minio/vendor/github.com/minio/dsync.lock.func1(0xc4203d2240, 0x4, 0xc420474080, 0x4, 0x4, 0xc4202abb60, 0x0, 0xa86d01, 0xefcfc0, 0xc420417a80)
    /go/src/github.com/minio/minio/vendor/github.com/minio/dsync/drwmutex.go:170 +0x69b
created by github.com/minio/minio/vendor/github.com/minio/dsync.lock
    /go/src/github.com/minio/minio/vendor/github.com/minio/dsync/drwmutex.go:191 +0xf4
```
master
Harshavardhana 8 years ago committed by GitHub
parent 3bcf7b7593
commit f234c35020
  1. 10
      cmd/namespace-lock.go

@ -33,13 +33,13 @@ var nsMutex *nsLockMap
func initDsyncNodes(eps []*url.URL) error {
cred := serverConfig.GetCredential()
// Initialize rpc lock client information only if this instance is a distributed setup.
var clnts []dsync.RPC
clnts := make([]dsync.RPC, len(eps))
myNode := -1
for _, ep := range eps {
for index, ep := range eps {
if ep == nil {
return errInvalidArgument
}
clnts = append(clnts, newAuthClient(&authConfig{
clnts[index] = newAuthClient(&authConfig{
accessKey: cred.AccessKeyID,
secretKey: cred.SecretAccessKey,
// Construct a new dsync server addr.
@ -48,9 +48,9 @@ func initDsyncNodes(eps []*url.URL) error {
// Construct a new rpc path for the endpoint.
path: pathutil.Join(lockRPCPath, getPath(ep)),
loginMethod: "Dsync.LoginHandler",
}))
})
if isLocalStorage(ep) && myNode == -1 {
myNode = len(clnts) - 1
myNode = index
}
}
return dsync.SetNodesWithClients(clnts, myNode)

Loading…
Cancel
Save