Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync #2

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ linters:
- cyclop
- depguard
- dupl
- dupword
- errname
- errorlint
- exhaustive
Expand Down Expand Up @@ -43,7 +42,6 @@ linters:
- testpackage
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
- varnamelen
Expand Down
12 changes: 11 additions & 1 deletion brotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ func WriteBrotliLevel(w io.Writer, p []byte, level int) (int, error) {
}
}

var stacklessWriteBrotli = stackless.NewFunc(nonblockingWriteBrotli)
var (
stacklessWriteBrotliOnce sync.Once
stacklessWriteBrotliFunc func(ctx interface{}) bool
)

func stacklessWriteBrotli(ctx interface{}) {
stacklessWriteBrotliOnce.Do(func() {
stacklessWriteBrotliFunc = stackless.NewFunc(nonblockingWriteBrotli)
})
stacklessWriteBrotliFunc(ctx)
}

func nonblockingWriteBrotli(ctxv interface{}) {
ctx := ctxv.(*compressCtx)
Expand Down
2 changes: 1 addition & 1 deletion bytesconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAppendHTMLEscape(t *testing.T) {
allcases[i] = byte(i)
}
res := string(AppendHTMLEscape(nil, string(allcases)))
expect := string(html.EscapeString(string(allcases)))
expect := html.EscapeString(string(allcases))
if res != expect {
t.Fatalf("unexpected string %q. Expecting %q.", res, expect)
}
Expand Down
5 changes: 3 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,7 @@ func (c *HostClient) acquireConn(reqTimeout time.Duration, connectionClose bool)
return nil, ErrNoFreeConns
}

//nolint:dupword
// reqTimeout c.MaxConnWaitTimeout wait duration
// d1 d2 min(d1, d2)
// 0(not set) d2 d2
Expand Down Expand Up @@ -2542,8 +2543,8 @@ func (c *PipelineClient) newConnClient() *pipelineConnClient {
}

// ErrPipelineOverflow may be returned from PipelineClient.Do*
// if the requests' queue is overflown.
var ErrPipelineOverflow = errors.New("pipelined requests' queue has been overflown. Increase MaxConns and/or MaxPendingRequests")
// if the requests' queue is overflowed.
var ErrPipelineOverflow = errors.New("pipelined requests' queue has been overflowed. Increase MaxConns and/or MaxPendingRequests")

// DefaultMaxPendingRequests is the default value
// for PipelineClient.MaxPendingRequests.
Expand Down
24 changes: 22 additions & 2 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,17 @@ func WriteGzipLevel(w io.Writer, p []byte, level int) (int, error) {
}
}

var stacklessWriteGzip = stackless.NewFunc(nonblockingWriteGzip)
var (
stacklessWriteGzipOnce sync.Once
stacklessWriteGzipFunc func(ctx interface{}) bool
)

func stacklessWriteGzip(ctx interface{}) {
stacklessWriteGzipOnce.Do(func() {
stacklessWriteGzipFunc = stackless.NewFunc(nonblockingWriteGzip)
})
stacklessWriteGzipFunc(ctx)
}

func nonblockingWriteGzip(ctxv interface{}) {
ctx := ctxv.(*compressCtx)
Expand Down Expand Up @@ -270,7 +280,17 @@ func WriteDeflateLevel(w io.Writer, p []byte, level int) (int, error) {
}
}

var stacklessWriteDeflate = stackless.NewFunc(nonblockingWriteDeflate)
var (
stacklessWriteDeflateOnce sync.Once
stacklessWriteDeflateFunc func(ctx interface{}) bool
)

func stacklessWriteDeflate(ctx interface{}) {
stacklessWriteDeflateOnce.Do(func() {
stacklessWriteDeflateFunc = stackless.NewFunc(nonblockingWriteDeflate)
})
stacklessWriteDeflateFunc(ctx)
}

func nonblockingWriteDeflate(ctxv interface{}) {
ctx := ctxv.(*compressCtx)
Expand Down
4 changes: 2 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ func (cm *inMemoryCacheManager) GetFileFromCache(cacheKind CacheKind, path strin
fileCache := cm.getFsCache(cacheKind)

cm.cacheLock.Lock()
ff, ok := fileCache[string(path)]
ff, ok := fileCache[path]
if ok {
ff.readersCount++
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ func (h *fsHandler) newFSFile(f fs.File, fileInfo fs.FileInfo, compressed bool,
}

func readFileHeader(f io.Reader, compressed bool, fileEncoding string) ([]byte, error) {
r := io.Reader(f)
r := f
var (
br *brotli.Reader
zr *gzip.Reader
Expand Down
2 changes: 1 addition & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,7 @@ func TestResponseBodyStream(t *testing.T) {
}
})

t.Run("limit response body size size", func(t *testing.T) {
t.Run("limit response body size", func(t *testing.T) {
t.Parallel()

client := Client{StreamResponseBody: true, MaxResponseBodySize: 20}
Expand Down
13 changes: 12 additions & 1 deletion stackless/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"sync"

"github.com/valyala/bytebufferpool"
)
Expand Down Expand Up @@ -98,7 +99,17 @@ func (w *writer) do(op op) error {

var errHighLoad = errors.New("cannot compress data due to high load")

var stacklessWriterFunc = NewFunc(writerFunc)
var (
stacklessWriterFuncOnce sync.Once
stacklessWriterFuncFunc func(ctx interface{}) bool
)

func stacklessWriterFunc(ctx interface{}) bool {
stacklessWriterFuncOnce.Do(func() {
stacklessWriterFuncFunc = NewFunc(writerFunc)
})
return stacklessWriterFuncFunc(ctx)
}

func writerFunc(ctx interface{}) {
w := ctx.(*writer)
Expand Down