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

【HELP】IN ErrorGroup use retry panic #986

Open
cwb2819259 opened this issue Mar 18, 2025 · 5 comments
Open

【HELP】IN ErrorGroup use retry panic #986

cwb2819259 opened this issue Mar 18, 2025 · 5 comments

Comments

@cwb2819259
Copy link

When I use the errorgroup package, panic occurs occasionally,I use version is : github.com/go-resty/resty/v2 v2.7.0

client is

var (
	hc     *http.Client 
	hcOnce sync.Once
)

func GetHC() *http.Client {
	hcOnce.Do(func() {
		hc = http_client.NewHttpClient()
		hc.Timeout = 3 * time.Second
	})
	return hc
}

func (l *Lark) Req() *resty.Request {
	client := resty.NewWithClient(GetHC()).SetRetryCount(1).SetLogger(NewLogger(l.ctx)).SetDebug(true).SetDebugBodyLimit(1000000)
	return client.R().SetContext(l.ctx).
		SetHeader("Content-Type", "application/json; charset=utf-8").
}

resp, err := l.Req().SetContext(ctx).Get(url + "&" + strings.Join(userIdsParams, "&"))

message: panic: runtime error: index out of range [104780] with length 104767
message: goroutine 131838 [running]:
message: bytes.(*Buffer).WriteByte(0xc007f7cb00?, 0x0?)
message: /usr/local/go/src/bytes/buffer.go:282 +0x87
message: encoding/json.Indent(0xc004c3d470, {0xc00b132000, 0x14151, 0x70550f0?}, {0x0, 0x0}, {0x433cdd8, 0x3})
message: /usr/local/go/src/encoding/json/indent.go:105 +0x33a
message: github.com/go-resty/resty/v2.(*Response).fmtBodyString(0xc000b5f6d0, 0xc001c86930?)
message: /workspace/vendor/github.com/go-resty/resty/v2/response.go:165 +0x1b4
message: github.com/go-resty/resty/v2.responseLogger(0xc0046823c0, 0xc000b5f6d0)
message: /workspace/vendor/github.com/go-resty/resty/v2/middleware.go:294 +0x1cc

@cwb2819259 cwb2819259 changed the title 【BUG】IN ErrorGroup use retry panic 【HELP】IN ErrorGroup use retry panic Mar 18, 2025
@jeevatkm
Copy link
Member

@cwb2819259 I think it is not related to the Resty package, maybe some issue with the body content plus based on the above trace it the Go standard library panics when handling the body content.

Also, I see you’re using an almost 4-year-old version of Resty. I would suggest upgrading to the latest version. Do not worry, there are no breaking changes.

@lib4u
Copy link

lib4u commented Mar 24, 2025

https://github.com/lib4u/grequest also for working with requests in golang

@jeevatkm
Copy link
Member

@cwb2819259 @lib4u Can you please try the latest version, v2.16.5, and let me know your feedback?

@cwb2819259
Copy link
Author

When I removed the SetDebug(true) method, the panic did not occur.
client := resty.NewWithClient(GetHC()).SetRetryCount(1).SetLogger(NewLogger(l.ctx)).SetDebugBodyLimit(1000000)

@jeevatkm
Copy link
Member

@cwb2819259 Are you using the latest version of Resty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants