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

os/exec: exec.Command("cat", "/proc/uptime") memory leak in golang 1.9 #27934

Closed
yxdming opened this issue Sep 29, 2018 · 4 comments
Closed

os/exec: exec.Command("cat", "/proc/uptime") memory leak in golang 1.9 #27934

yxdming opened this issue Sep 29, 2018 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@yxdming
Copy link

yxdming commented Sep 29, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.9

What operating system and processor architecture are you using (go env)?

SuSE

What did you do?

When i use exec.Command("cat", "/proc/uptime") in my programe, i found that there is a memory leak in this call. The memory used by program goes high after 2 hours from initial 20MB to 105MB and increasing continuously unless i restart the programe. The code as below.

func GetSecondFromSystemStart() int {
	out, err := exec.Command("cat", "/proc/uptime").Output()
	if(err != nil){
		logger.ErrorLog(MODULE_NAME, "get time from start fail:%s", err.Error())
	}else{
		vTimeString := strings.Split(string(out), ".")
		if(len(vTimeString) == 0){
			logger.ErrorLog(MODULE_NAME, "get time from start fail")
		}else{
			sed, e := strconv.Atoi(vTimeString[0])
			if(e != nil){
				logger.ErrorLog(MODULE_NAME, "get time from start fail:%s", e.Error())
			}else{
				logger.DebugLog(MODULE_NAME, "get time from start:%d", sed)
				return sed
			}
		}
	}
	return 0
}
@ALTree ALTree changed the title exec.Command("cat", "/proc/uptime") memory leak in golang 1.9 os/exec: exec.Command("cat", "/proc/uptime") memory leak in golang 1.9 Sep 29, 2018
@ALTree ALTree added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 29, 2018
@ALTree
Copy link
Member

ALTree commented Sep 29, 2018

Can you reproduce this with Go 1.11 (https://golang.org/dl)? Go1.9 is quite old and it's no longer maintained.

@mvdan
Copy link
Member

mvdan commented Sep 29, 2018

Also please check your pprof memory profiles. If the number of in-use heap objects keeps increasing over time, it will tell you where the allocations are coming from.

@bradfitz
Copy link
Contributor

bradfitz commented Oct 2, 2018

Unrelated: it's much more efficient to use ioutil.ReadFile to read /proc/uptime instead of starting a child process.

But in any case, the code above shouldn't leak anything. Please provide a minimal repro to demonstrate the problem.

@yxdming
Copy link
Author

yxdming commented Oct 12, 2018

@ALTree
Thanks.
When i use Go 1.11, it seam that everything works better. I will test more times and close this issue if the memory doesn't increase any more.

@yxdming yxdming closed this as completed Oct 12, 2018
@golang golang locked and limited conversation to collaborators Oct 12, 2019
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