storagenode/nodestats: fix issue on 32 bit platforms (#2841)
* storagenode/nodestats: fix issue on 32 bit platforms time.Duration is an int64, so casting it down to an int can cause it to become negative, causing a panic. Change-Id: I33da7c29ddd59be60d8deec944a25f4a025902c7 * storagenode/nodestats: fix lint issue in test Change-Id: Ie68598d724d2cae0dc959d4877098a08f4eb9af7
This commit is contained in:
parent
2d69d47655
commit
14e36e4d60
@ -146,7 +146,7 @@ func (cache *Cache) sleep(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
jitter := time.Duration(rand.Intn(int(cache.maxSleep)))
|
jitter := time.Duration(rand.Int63n(int64(cache.maxSleep)))
|
||||||
if !sync2.Sleep(ctx, jitter) {
|
if !sync2.Sleep(ctx, jitter) {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
18
storagenode/nodestats/cache_test.go
Normal file
18
storagenode/nodestats/cache_test.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Copyright (C) 2019 Storj Labs, Inc.
|
||||||
|
// See LICENSE for copying information.
|
||||||
|
|
||||||
|
package nodestats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCacheSleep32bitBug(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Ensure that a large maxSleep doesn't roll over to negative values on 32 bit systems.
|
||||||
|
_ = (&Cache{maxSleep: 1 << 32}).sleep(ctx)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user