Merge pull request #15100 from calavera/fix_reader_timeout
Fix reset timeout for buffer readers.
This commit is contained in:
commit
9f198e9313
1 changed files with 8 additions and 9 deletions
|
@ -2,15 +2,18 @@ package ioutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/rand"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/random"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var rndSrc = random.NewSource()
|
||||||
|
|
||||||
type readCloserWrapper struct {
|
type readCloserWrapper struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
closer func() error
|
closer func() error
|
||||||
|
@ -66,18 +69,14 @@ type bufReader struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBufReader(r io.Reader) *bufReader {
|
func NewBufReader(r io.Reader) *bufReader {
|
||||||
var timeout int
|
timeout := rand.New(rndSrc).Intn(120) + 180
|
||||||
if randVal, err := rand.Int(rand.Reader, big.NewInt(120)); err == nil {
|
|
||||||
timeout = int(randVal.Int64()) + 180
|
|
||||||
} else {
|
|
||||||
timeout = 300
|
|
||||||
}
|
|
||||||
reader := &bufReader{
|
reader := &bufReader{
|
||||||
buf: &bytes.Buffer{},
|
buf: &bytes.Buffer{},
|
||||||
drainBuf: make([]byte, 1024),
|
drainBuf: make([]byte, 1024),
|
||||||
reuseBuf: make([]byte, 4096),
|
reuseBuf: make([]byte, 4096),
|
||||||
maxReuse: 1000,
|
maxReuse: 1000,
|
||||||
resetTimeout: time.Second * time.Duration(timeout),
|
resetTimeout: time.Duration(timeout) * time.Second,
|
||||||
bufLenResetThreshold: 100 * 1024,
|
bufLenResetThreshold: 100 * 1024,
|
||||||
maxReadDataReset: 10 * 1024 * 1024,
|
maxReadDataReset: 10 * 1024 * 1024,
|
||||||
reader: r,
|
reader: r,
|
||||||
|
|
Loading…
Reference in a new issue