Vet/race fixes (#4421)

This addresses all found vet/race fixes in community edition.

---------

Co-authored-by: Damian Debkowski <damian.debkowski@hashicorp.com>
This commit is contained in:
Jeff MitchellandDamian Debkowski authored and GitHub committed 2024-02-21 16:32:26 -05:00
1 parent 4535af25aa
commit 014a5a7aae
46 files changed
+411 -176

No files matched your search

@@ -14,6 +14,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/hashicorp/boundary/api"
@@ -62,7 +63,7 @@ type CacheServer struct {
info map[string]string
storeUrl string
store *db.DB
store atomic.Pointer[db.DB]
tickerWg *sync.WaitGroup
httpSrv *http.Server
@@ -224,9 +225,13 @@ func (s *CacheServer) Serve(ctx context.Context, cmd Commander, opt ...Option) e
s.info["Store debug"] = strconv.FormatBool(s.conf.StoreDebug)
s.infoKeys = append(s.infoKeys, "Store debug")
if s.store, s.storeUrl, err = openStore(ctx, s.conf.DatabaseUrl, s.conf.StoreDebug); err != nil {
var store *db.DB
store, s.storeUrl, err = openStore(ctx, s.conf.DatabaseUrl, s.conf.StoreDebug)
if err != nil {
return errors.Wrap(ctx, err, op)
}
s.store.Store(store)
if s.storeUrl != "" {
s.info["Database URL"] = s.storeUrl
s.infoKeys = append(s.infoKeys, "Database URL")
@@ -260,7 +265,7 @@ func (s *CacheServer) Serve(ctx context.Context, cmd Commander, opt ...Option) e
s.printInfo(ctx)
repo, err := cache.NewRepository(ctx, s.store, &sync.Map{}, cmd.ReadTokenFromKeyring, opts.withBoundaryTokenReaderFunc)
repo, err := cache.NewRepository(ctx, s.store.Load(), &sync.Map{}, cmd.ReadTokenFromKeyring, opts.withBoundaryTokenReaderFunc)
if err != nil {
return errors.Wrap(ctx, err, op)
}
@@ -71,7 +71,7 @@ func (s *TestServer) Serve(t *testing.T, opt ...Option) error {
func (s *TestServer) AddKeyringToken(t *testing.T, address, keyring, tokenName, tokenId string, atReadFn cache.BoundaryTokenReaderFn) {
t.Helper()
ctx := context.Background()
r, err := cache.NewRepository(ctx, s.CacheServer.store, &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
r, err := cache.NewRepository(ctx, s.CacheServer.store.Load(), &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
require.NoError(t, err)
require.NoError(t, r.AddKeyringToken(ctx, address, cache.KeyringToken{
@@ -86,7 +86,7 @@ func (s *TestServer) AddKeyringToken(t *testing.T, address, keyring, tokenName,
func (s *TestServer) AddResources(t *testing.T, p *authtokens.AuthToken, tars []*targets.Target, sess []*sessions.Session, atReadFn cache.BoundaryTokenReaderFn) {
t.Helper()
ctx := context.Background()
r, err := cache.NewRepository(ctx, s.CacheServer.store, &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
r, err := cache.NewRepository(ctx, s.CacheServer.store.Load(), &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
require.NoError(t, err)
tarFn := func(ctx context.Context, _, tok string, _ cache.RefreshTokenValue) ([]*targets.Target, []string, cache.RefreshTokenValue, error) {
@@ -113,7 +113,7 @@ func (s *TestServer) AddResources(t *testing.T, p *authtokens.AuthToken, tars []
func (s *TestServer) AddUnsupportedCachingData(t *testing.T, p *authtokens.AuthToken, atReadFn cache.BoundaryTokenReaderFn) {
t.Helper()
ctx := context.Background()
r, err := cache.NewRepository(ctx, s.CacheServer.store, &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
r, err := cache.NewRepository(ctx, s.CacheServer.store.Load(), &sync.Map{}, s.cmd.ReadTokenFromKeyring, atReadFn)
require.NoError(t, err)
tarFn := func(ctx context.Context, _, tok string, _ cache.RefreshTokenValue) ([]*targets.Target, []string, cache.RefreshTokenValue, error) {
@@ -37,7 +37,6 @@ type refreshTicker struct {
refreshInterval time.Duration
recheckSupportInterval time.Duration
randomizationFactor float64
rand *rand.Rand
refreshChan chan struct{}
refresher refreshService
}
@@ -80,7 +79,6 @@ func newRefreshTicker(ctx context.Context, refresh refreshService, opt ...Option
refreshInterval: refreshInterval,
recheckSupportInterval: recheckSupportInterval,
randomizationFactor: randomizationFactor,
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
refresher: refresh,
// We make this channel size 1 so if something happens midway through the refresh
@@ -151,12 +149,12 @@ func (rt *refreshTicker) nextIntervalWithRandomness(d time.Duration) time.Durati
return d
}
randFactor := rt.rand.Float64()
randFactor := rand.Float64()
randFactor = randFactor * rt.randomizationFactor
randDur := randFactor * float64(d)
// Half a chance to be faster, not slower
if rt.rand.Float32() > 0.5 {
if rand.Float32() > 0.5 {
randDur = -1 * randDur
}
return d + time.Duration(randDur)