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

chore: add debug log for HERTZ_DISABLE_REQUEST_CONTEXT_POOL env #1226

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions pkg/protocol/http1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server/render"
errs "github.com/cloudwego/hertz/pkg/common/errors"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/hertz/pkg/common/tracer/stats"
"github.com/cloudwego/hertz/pkg/common/tracer/traceinfo"
"github.com/cloudwego/hertz/pkg/common/utils"
Expand All @@ -44,7 +45,8 @@ import (

func init() {
if b, err := utils.GetBoolFromEnv("HERTZ_DISABLE_REQUEST_CONTEXT_POOL"); err == nil {
disabaleRequestContextPool = b
hlog.Infof("HERTZ_DISABLE_REQUEST_CONTEXT_POOL env is set to %t", b)
disableRequestContextPool = b
}
}

Expand All @@ -59,7 +61,7 @@ var (
errShortConnection = errs.New(errs.ErrShortConnection, errs.ErrorTypePublic, "server is going to close the connection")
errUnexpectedEOF = errs.NewPublic(io.ErrUnexpectedEOF.Error() + " when reading request")

disabaleRequestContextPool = false
disableRequestContextPool = false
)

type Option struct {
Expand Down Expand Up @@ -90,14 +92,14 @@ type Server struct {
}

func (s Server) getRequestContext() *app.RequestContext {
if disabaleRequestContextPool {
if disableRequestContextPool {
return &app.RequestContext{}
}
return s.Core.GetCtxPool().Get().(*app.RequestContext)
}

func (s Server) putRequestContext(ctx *app.RequestContext) {
if disabaleRequestContextPool {
if disableRequestContextPool {
return
}
ctx.Reset()
Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/http1/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ func TestServerDisableReqCtxPool(t *testing.T) {
defaultConn := mock.NewConn("GET / HTTP/1.1\nHost: foobar.com\n\n")
err := server.Serve(context.TODO(), defaultConn)
assert.Nil(t, err)
disabaleRequestContextPool = true
disableRequestContextPool = true
defer func() {
// reset global variable
disabaleRequestContextPool = false
disableRequestContextPool = false
}()
server.Core = &mockCore{
ctxPool: &sync.Pool{New: func() interface{} {
Expand Down
Loading