Skip to content

crypto/sha256: memory leak or issue with heap profiler #30249

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

Closed
ebuchman opened this issue Feb 15, 2019 · 4 comments
Closed

crypto/sha256: memory leak or issue with heap profiler #30249

ebuchman opened this issue Feb 15, 2019 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@ebuchman
Copy link

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

$ go version
go version go1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes (1.11.5)

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

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

package main

import (
	"crypto/sha256"
	"fmt"
	"net/http"
	_ "net/http/pprof"
	"runtime"
)

func main() {
	runtime.MemProfileRate = 1
	myFunc()
	runtime.GC()
	fmt.Println(http.ListenAndServe("localhost:7070", nil))
}

func myFunc() {
	sha256.New()
}

Then check heap profile: http://localhost:7070/debug/pprof/heap?debug=1

What did you expect to see?

No entry for myFunc

What did you see instead?

0: 0 [1: 128] @ 0x107563d 0x1300102 0x1300061 0x102ee57 0x105ca71
#	0x107563c	crypto/sha256.New+0x2c	/Users/myuser/goRoot/1.11.5/src/crypto/sha256/sha256.go:181
#	0x1300101	main.myFunc+0x21	/Users/myuser/goApps/src/github.com/tendermint/tendermint/pprof/main.go:19
#	0x1300060	main.main+0x30		/Users/myuser/goApps/src/github.com/tendermint/tendermint/pprof/main.go:13
#	0x102ee56	runtime.main+0x206	/Users/myuser/goRoot/1.11.5/src/runtime/proc.go:201

Note this issue also holds for sha512, but not for sha1, and not for ripemd160 from x/crypto

@FiloSottile FiloSottile changed the title sha256: memory leak or issue with heap profiler crypto/sha256: memory leak or issue with heap profiler Feb 15, 2019
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 15, 2019
@FiloSottile FiloSottile added this to the Go1.13 milestone Feb 15, 2019
@odeke-em
Copy link
Member

odeke-em commented Feb 17, 2019

Thank you for filing this issue @ebuchman and welcome to the Go project!

I shall kindly page some runtime folks to take a look: /cc @RLH @aclements @randall77

@davecheney
Copy link
Contributor

@ebuchman sha256.New returns a value boxed inside a hash.Hash interface. The value allocated by sha256.New has escaped to the heap -- you can verify that with go build -gcflags=-m

Why did you expect this code to not allocate a value on the heap? Is it because you are not using the result from sha256.New?

@FiloSottile
Copy link
Contributor

The confusion might be due to the fact that the heap profile raw format includes all allocated values, live and collected. To see if it's still live after GC, use go tool pprof -inuse_objects.

@rsc
Copy link
Contributor

rsc commented Apr 23, 2019

There's no leak here. Run this in a loop and you will see that the heap is not growing. The "0: 0" in the raw format means there are none of them live now.

@rsc rsc closed this as completed Apr 23, 2019
@golang golang locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants