mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix reset timeout for buffer readers.
Use our goroutine-safe random source. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
c473ae14fd
commit
40ea67a596
1 changed files with 8 additions and 9 deletions
|
@ -2,15 +2,18 @@ package ioutils
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/random"
|
||||
)
|
||||
|
||||
var rndSrc = random.NewSource()
|
||||
|
||||
type readCloserWrapper struct {
|
||||
io.Reader
|
||||
closer func() error
|
||||
|
@ -66,18 +69,14 @@ type bufReader struct {
|
|||
}
|
||||
|
||||
func NewBufReader(r io.Reader) *bufReader {
|
||||
var timeout int
|
||||
if randVal, err := rand.Int(rand.Reader, big.NewInt(120)); err == nil {
|
||||
timeout = int(randVal.Int64()) + 180
|
||||
} else {
|
||||
timeout = 300
|
||||
}
|
||||
timeout := rand.New(rndSrc).Intn(120) + 180
|
||||
|
||||
reader := &bufReader{
|
||||
buf: &bytes.Buffer{},
|
||||
drainBuf: make([]byte, 1024),
|
||||
reuseBuf: make([]byte, 4096),
|
||||
maxReuse: 1000,
|
||||
resetTimeout: time.Second * time.Duration(timeout),
|
||||
resetTimeout: time.Duration(timeout) * time.Second,
|
||||
bufLenResetThreshold: 100 * 1024,
|
||||
maxReadDataReset: 10 * 1024 * 1024,
|
||||
reader: r,
|
||||
|
|
Loading…
Reference in a new issue