golang/go

embed: unable to read embedded files and directories

Opened this issue · 5 comments

Go version

go version go1.25.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/ibrahim/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/ibrahim/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/g2/dgdzq5s16r5gzxwkk3xv9vd00000gn/T/go-build1761144713=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/ibrahim/go/pkg/mod'
GONOPROXY='github.com/mattermost/*'
GONOSUMDB='github.com/mattermost/*'
GOOS='darwin'
GOPATH='/Users/ibrahim/go'
GOPRIVATE='github.com/mattermost/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.25.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/ibrahim/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='go1.25.1'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.25.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I have embedded sql queries in my Go application and we read those queries from embedded files during runtime. It's a standard embedding process with following snippet:

import "embed"

//go:embed *
var assets embed.FS

func Assets() embed.FS {
	return assets
}

And I am reading one of the directory as follows:

// assets is a embed.FS instance

queries, err := assets.ReadDir(path.Join("dir", "subdir"))
if err != nil {
	return err
}

What did you see happen?

If I compile this binary with GOTOOLCHAIN=go1.24.6 for example it works fine and the program is able to read files, but when I try compile with GOTOOLCHAIN=go1.25.1, program basically can't read any files without producing any errors. In the code snippet above queries returns an empty slice.

output_compile_go1.24.6.txt

output_compile_go1.25.1.txt

What did you expect to see?

Embedded files should be accessible regardless of the toolchain as I couldn't find any related release note regarding to the issue.

please show a complete reproducer.

please show a complete reproducer.

@seankhliao What do you mean by complete reproducer? If it's the code, then you can find it here: https://github.com/mattermost/migration-assist/blob/main/internal/store/store.go#L146

But I asked a colleague they are not observing the same behavior on Linux. I'm not sure if it's related to macos or my env.

It sounds more than likely to be a problem in your local environment.
Unless you have a way for us to reproduce the issue, there's very little we can do.

@seankhliao right, I'll try to reproduce the issue elsewhere, meanwhile can you guide me to understand what may gone wrong? Any pointer to collect logs or look into intermediary files during the compilation? Because on the surface of things, there is no apparent errors. I have two different compiler which are officially built and unfortunately different behaviors.

Or let me phrase the question differently; with the same code is there a way that I can get this behavior with any setting/flags in my environment?