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

It seems memory leaks with post #753

Open
youzeliang opened this issue Nov 21, 2023 · 3 comments
Open

It seems memory leaks with post #753

youzeliang opened this issue Nov 21, 2023 · 3 comments

Comments

@youzeliang
Copy link

In most cases, I use the resty library's Post method to send POST requests, and everything works fine with no issues. However, in a particular scenario, when I receive a large response structure, I encounter a memory leak. Firstly, I want to clarify that my code doesn't have any goroutine leaks or lingering global variables (i.e., no delayed releases). Upon using pprof to inspect, it seems that the underlying io.readAll operation is consuming a significant amount of memory. Are there considerations for optimizing this part? I will attach my pprof results and some key information along with the crucial parts of the code.

profile001

image

resty.New(). OnBeforeRequest(func(client *resty.Client, r *resty.Request) error { return nil }). SetRetryCount(2). SetTimeout(time.Second * 8). R(). SetFormData(apiBody). SetResult(&apiRes). Post(url)

the response apiRes is about 4k

@jeevatkm
Copy link
Member

@youzeliang Thanks for reaching out. I'm currently on vacation days; I will be back in January.

@trungdlp-wolffun
Copy link

trungdlp-wolffun commented Jan 11, 2024

I see that code in resty/v2:

func closeq(v interface{}) {
	if c, ok := v.(io.Closer); ok {
		silently(c.Close())
	}
}

func silently(_ ...interface{}) {}

See client.go#12000

@jeevatkm
Copy link
Member

jeevatkm commented Mar 2, 2024

@youzeliang Thanks for reaching out. Based on the above details. Currently the method R().SetFormData reads all the form data values into memory to create Request body for the request. That's why memory increases.

In the v3, there are plans to optimize the flow.

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

No branches or pull requests

3 participants