Skip to content

init() runs more than once when using Fiber's Prefork feature: language bug or undocumented quirk? #73393

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
selamba opened this issue Apr 15, 2025 · 4 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@selamba
Copy link

selamba commented Apr 15, 2025

Go version

go version go1.24.0 windows/amd64

Output of go env in your module/workspace:

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=on
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\User\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\User\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\User\AppData\Local\Temp\go-build1004090984=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=C:\Jetbrains\projects\train-booking-vertical-slice\go.mod
set GOMODCACHE=C:\Users\User\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\User\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:/Users/User/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.windows-amd64
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\User\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\User\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.24.0.windows-amd64\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.0
set GOWORK=
set PKG_CONFIG=pkg-config

What did you do?

Was writing a nondescript train booking service implementation. I used init() in one of my packages. It prints text using fmt.Println.

Entire source code is in the attached archive.

What did you see happen?

Text from init() gets printed several times.

What did you expect to see?

Text from init() gets printed only once, as it should.

@selamba
Copy link
Author

selamba commented Apr 15, 2025

@selamba
Copy link
Author

selamba commented Apr 15, 2025

Disabling Prefork in fiber.Config fixes this issue. I think this warrants some explanation and documentation.

@selamba selamba changed the title init() runs more than once init() runs more than once when using Fiber's Prefork feature: language bug or undocumented quirk? Apr 15, 2025
@gopherbot gopherbot added the Documentation Issues describing a change to documentation. label Apr 15, 2025
@selamba
Copy link
Author

selamba commented Apr 15, 2025

Why did you do that gopherbot

@mvdan mvdan removed the Documentation Issues describing a change to documentation. label Apr 15, 2025
@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 15, 2025
@seankhliao
Copy link
Member

seankhliao commented Apr 16, 2025

I think this is a question for fiber.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2025
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.
Projects
None yet
Development

No branches or pull requests

5 participants