Skip to content
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
8 changes: 6 additions & 2 deletions pkg/protocols/common/protocolstate/memguardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ var (
MaxBytesBufferAllocOnLowMemory = env.GetEnvOrDefault("MEMGUARDIAN_ALLOC", 0)
memTimer *time.Ticker
cancelFunc context.CancelFunc
muGlobalChange sync.Mutex
)

func StartActiveMemGuardian(ctx context.Context) {
muGlobalChange.Lock()
defer muGlobalChange.Unlock()
if memguardian.DefaultMemGuardian == nil || memTimer != nil {
return
}
Expand All @@ -42,6 +45,9 @@ func StartActiveMemGuardian(ctx context.Context) {
}

func StopActiveMemGuardian() {
muGlobalChange.Lock()
defer muGlobalChange.Unlock()

if memguardian.DefaultMemGuardian == nil {
return
}
Expand Down Expand Up @@ -73,8 +79,6 @@ func GuardThreadsOrDefault(current int) int {
return 1
}

var muGlobalChange sync.Mutex

// Global setting
func GlobalGuardBytesBufferAlloc() error {
if !muGlobalChange.TryLock() {
Expand Down
6 changes: 4 additions & 2 deletions pkg/protocols/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,10 @@ func (request *Request) executeRequest(input *contextargs.Context, generatedRequ
var curlCommand string
if !request.Unsafe && resp != nil && generatedRequest.request != nil && resp.Request != nil && !request.Race {
bodyBytes, _ := generatedRequest.request.BodyBytes()
resp.Request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
command, err := http2curl.GetCurlCommand(generatedRequest.request.Request)
// Use a clone to avoid a race condition with the http transport
req := resp.Request.Clone(resp.Request.Context())
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
command, err := http2curl.GetCurlCommand(req)
if err == nil && command != nil {
curlCommand = command.String()
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/protocols/http/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
// dump creates a dump of the http request in form of a byte slice
func dump(req *generatedRequest, reqURL string) ([]byte, error) {
if req.request != nil {
bin, err := req.request.Dump()
// Use a clone to avoid a race condition with the http transport
bin, err := req.request.Clone(req.request.Context()).Dump()
if err != nil {
return nil, errorutil.NewWithErr(err).WithTag("http").Msgf("could not dump request: %v", req.request.String())
}
Expand Down
Loading