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

runtime/pprof: pprof.Profile WriteTo does not check for the error, and return success on errors #73107

Open
DVasselli opened this issue Mar 31, 2025 · 2 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@DVasselli
Copy link

Go version

go version go1.24.1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/danielevasselli/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/danielevasselli/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/gj/lj4jxkh50tg49ht49djz8y3w0000gp/T/go-build916792291=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/danielevasselli/playground/profile/go.mod'
GOMODCACHE='/Users/danielevasselli/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/danielevasselli/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/Users/danielevasselli/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I performed a heap lookup, and tried to perform a write to a custom writer, which returned an error

Demo code: https://go.dev/play/p/uaNjHnwqiJh

What did you see happen?

The function WriteTo returned no error even though the provided writer errored out.

Demo code: https://go.dev/play/p/uaNjHnwqiJh

What did you expect to see?

I expected the function to return the error as per its godoc

If a write to w returns an error, WriteTo returns that error.

Stack trace of the calls

compress/gzip.(*Writer).Write(0x1400009c460, {0x14000198000, 0x429, 0x580})
	/opt/homebrew/Cellar/go/1.24.1/libexec/src/compress/gzip/gzip.go:168 +0x154
runtime/pprof.(*profileBuilder).build(0x14000186000)
	/opt/homebrew/Cellar/go/1.24.1/libexec/src/runtime/pprof/proto.go:390 +0x488
runtime/pprof.writeHeapProto({0x1025f2fc0?, 0x10272e3c0?}, {0x14000180008, 0x2, 0x0?}, 0x80000, {0x0, 0x0})
	/opt/homebrew/Cellar/go/1.24.1/libexec/src/runtime/pprof/protomem.go:66 +0x454
runtime/pprof.writeHeapInternal({0x1025f2fc0, 0x10272e3c0}, 0x0, {0x0, 0x0})
	/opt/homebrew/Cellar/go/1.24.1/libexec/src/runtime/pprof/pprof.go:634 +0x234
runtime/pprof.writeHeap({0x1025f2fc0?, 0x10272e3c0?}, 0xbf044b1c1fe20cd9?)
	/opt/homebrew/Cellar/go/1.24.1/libexec/src/runtime/pprof/pprof.go:593 +0x2c
runtime/pprof.(*Profile).WriteTo(0x10256443f?, {0x1025f2fc0?, 0x10272e3c0?}, 0x67ea86f8?)
	/opt/homebrew/Cellar/go/1.24.1/libexec/src/runtime/pprof/pprof.go:377 +0x14c

The call to writer provided happens here. That function returns the error that is not checked here

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 31, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Mar 31, 2025
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 31, 2025
@cagedmantis cagedmantis added this to the Go1.25 milestone Mar 31, 2025
@rittneje
Copy link
Contributor

rittneje commented Mar 31, 2025

In addition to the line you highlighted, the current implemention also neglects to consider the return value from b.zw.Close().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants