Skip to content

Commit

Permalink
Merge remote-tracking branch 'oss/master' into required-params
Browse files Browse the repository at this point in the history
* oss/master:
  Add seal type to seal-status output. (#3516)
  Use an atomic store in expiration loading test to fix race detector
  fix deadlock while loading groups (#3515)
  changelog++
  Fix memory leak when a connection would hit the cluster port and go away (#3513)
  • Loading branch information
Chris Hoffman committed Nov 2, 2017
2 parents a9e3792 + 962ef74 commit 34953bb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ BUG FIXES:
* api: Fix panic when setting a custom HTTP client but with a nil transport
[GH-3437]
* auth/radius: Fix logging in in some situations [GH-3461]
* core: Fix memleak when a connection would connect to the cluster port and
then go away [GH-3513]
* physical/etcd3: Fix some listing issues due to how etcd3 does prefix
matching [GH-3406]
* physical/file: Fix listing when underscores are the first component of a
Expand Down
1 change: 1 addition & 0 deletions api/sys_seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func sealStatusRequest(c *Sys, r *Request) (*SealStatusResponse, error) {
}

type SealStatusResponse struct {
Type string `json:"type"`
Sealed bool `json:"sealed"`
T int `json:"t"`
N int `json:"n"`
Expand Down
4 changes: 3 additions & 1 deletion command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ func (c *StatusCommand) Run(args []string) int {
}

outStr := fmt.Sprintf(
"Sealed: %v\n"+
"Type: %s\n"+
"Sealed: %v\n"+
"Key Shares: %d\n"+
"Key Threshold: %d\n"+
"Unseal Progress: %d\n"+
"Unseal Nonce: %v\n"+
"Version: %s",
sealStatus.Type,
sealStatus.Sealed,
sealStatus.N,
sealStatus.T,
Expand Down
2 changes: 2 additions & 0 deletions http/sys_seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func handleSysSealStatusRaw(core *vault.Core, w http.ResponseWriter, r *http.Req
progress, nonce := core.SecretProgress()

respondOk(w, &SealStatusResponse{
Type: sealConfig.Type,
Sealed: sealed,
T: sealConfig.SecretThreshold,
N: sealConfig.SecretShares,
Expand All @@ -202,6 +203,7 @@ func handleSysSealStatusRaw(core *vault.Core, w http.ResponseWriter, r *http.Req
}

type SealStatusResponse struct {
Type string `json:"type"`
Sealed bool `json:"sealed"`
T int `json:"t"`
N int `json:"n"`
Expand Down
8 changes: 4 additions & 4 deletions vault/identity_store_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (i *IdentityStore) loadGroups() error {
}
i.logger.Debug("identity: groups collected", "num_existing", len(existing))

i.groupLock.Lock()
defer i.groupLock.Unlock()

for _, key := range existing {
bucket, err := i.groupPacker.GetBucket(i.groupPacker.BucketPath(key))
if err != nil {
Expand All @@ -83,14 +86,11 @@ func (i *IdentityStore) loadGroups() error {
i.logger.Trace("loading group", "name", group.Name, "id", group.ID)
}

i.groupLock.Lock()
defer i.groupLock.Unlock()

txn := i.db.Txn(true)
defer txn.Abort()

err = i.upsertGroupInTxn(txn, group, false)
if err != nil {
txn.Abort()
return fmt.Errorf("failed to update group in memdb: %v", err)
}

Expand Down
23 changes: 12 additions & 11 deletions vault/request_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ func (c *Core) startForwarding() error {

// Accept the connection
conn, err := tlsLn.Accept()
if conn != nil {
// Always defer although it may be closed ahead of time
defer conn.Close()
}
if err != nil {
if err != nil || conn == nil {
if conn != nil {
conn.Close()
}
continue
}

Expand All @@ -138,9 +137,7 @@ func (c *Core) startForwarding() error {
if c.logger.IsDebug() {
c.logger.Debug("core: error handshaking cluster connection", "error", err)
}
if conn != nil {
conn.Close()
}
conn.Close()
continue
}

Expand All @@ -153,10 +150,14 @@ func (c *Core) startForwarding() error {

c.logger.Trace("core: got request forwarding connection")
c.clusterParamsLock.RLock()
go fws.ServeConn(conn, &http2.ServeConnOpts{
Handler: c.rpcServer,
})
rpcServer := c.rpcServer
c.clusterParamsLock.RUnlock()
go func() {
defer conn.Close()
fws.ServeConn(conn, &http2.ServeConnOpts{
Handler: rpcServer,
})
}()

default:
c.logger.Debug("core: unknown negotiated protocol on cluster port")
Expand Down
3 changes: 2 additions & 1 deletion vault/token_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -567,7 +568,7 @@ func TestTokenStore_CreateLookup_ExpirationInRestoreMode(t *testing.T) {

// Reset expiration manager to restore mode
ts.expiration.restoreModeLock.Lock()
ts.expiration.restoreMode = 1
atomic.StoreInt32(&ts.expiration.restoreMode, 1)
ts.expiration.restoreLocks = locksutil.CreateLocks()
ts.expiration.restoreModeLock.Unlock()

Expand Down

0 comments on commit 34953bb

Please sign in to comment.