Skip to content

os: Root can no longer be safely copied in Go 1.25 #74574

Open
@fastcat

Description

@fastcat

Go version

1.25rc2

Output of go env in your module/workspace:

`go env` output, not particularly relevant
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/cheetah/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/cheetah/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1694165664=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/cheetah/src/gdev/go.mod'
GOMODCACHE='/home/cheetah/.go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/cheetah/.go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/cheetah/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25rc2.linux-amd64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/cheetah/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/cheetah/.go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25rc2.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25rc2'
GOWORK='/home/cheetah/src/gdev/go.work'
PKG_CONFIG='pkg-config'

What did you do?

I (mistakenly) tried to do a struct embedding of an os.Root in my application, and then got confused when I got file already closed errors.

Since os.OpenRoot attaches a Cleanup to the *os.Root pointer returned that calls *os.Root.Close() once freed,, it's important that no struct copies be made, as those copies won't work properly.

What did you see happen?

file already closed errors when my os.Root instance was still live in active goroutine stacks

What did you expect to see?

Some combination of:

  1. A documentation note that the struct is not safe to copy
  2. A vet error telling me that same thing

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions