Navigation Menu

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

http client memory leak #32143

Closed
0x000777 opened this issue May 19, 2019 · 4 comments
Closed

http client memory leak #32143

0x000777 opened this issue May 19, 2019 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@0x000777
Copy link

This code has a memory leak. Memory grows with every request.

package main

import (
	"fmt"
	"net/http"
	"io"
	"io/ioutil"
	"time"
)
func main() {
	httpClient := &http.Client{}

	for {
		res, err := httpClient.Get("https://google.com/")
		if err != nil {
			return
		}

		io.Copy(ioutil.Discard, res.Body)

		fmt.Println(res.StatusCode)

		time.Sleep( time.Second * 1 )
		res.Body.Close()
	}
}
@ALTree
Copy link
Member

ALTree commented May 19, 2019

Memory grows with every request.

How are you measuring this? Please include details. You also didn't fill out the issue template. Which OS are you on? What Go version are you using?

@ALTree ALTree added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 19, 2019
@AlexRouSg
Copy link
Contributor

@ALTree he has a closed issue on the same topic with a little more detail.
#32110

go version go1.12.5 windows/amd64

@0x000777
Copy link
Author

go version go1.12.5 windows/amd64

After each request, the memory is increased, but not cleared. After 8 hours - 8 gigabytes ends and the program ends. What else to write here, the example code is given, it remains only to run and see. Yes, the application is opened a second time, because the first one was closed, without even understanding it.

@agnivade
Copy link
Contributor

Your first issue was closed because your code was erroneous. With the correct code, I am unable to reproduce the issue (I am on linux though).

You still haven't mentioned how are you measuring the memory increase. Can you mention that ?

@golang golang locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants