Skip to content

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

Closed
@DVasselli

Description

@DVasselli

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

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions