Skip to content

slog.SetDefault kills the process when running in ARMv8 platform configuration #75752

@stunney

Description

@stunney

Go version

1.25.1

Output of go env in your module/workspace:

AR='ar'
CC='aarch64-linux-gnu-gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build190822621=/tmp/go-build -gno-record-gcc-switches'       
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/go.mod'
GOMODCACHE='/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

With the provided code at https://github.com/stunney/bug_golang_slog_armv8_processdeath

I create a armv8 container for my program which is compiled to on an armv8 platform, explicitly targeting ARMv8.

Here is my simple main.go that I have extracted from a larger project to show the issue:

package main

import (
	"log"
	"log/slog"
	"os"

	"github.com/natefinch/lumberjack"
)

func ConfigureServiceLogging() {
	log.Println("ConfigureServiceLogging::start")

	log.Println("ConfigureServiceLogging::defineRotator")
	// Configure Lumberjack for log rotation
	logRotator := &lumberjack.Logger{
		Filename:   os.Getenv("LOG_DIR"), // Name of the log file
		MaxSize:    10,                   // Max size in megabytes before rotation
		MaxBackups: 3,                    // Max number of old log files to keep
		MaxAge:     7,                    // Max number of days to retain old log files
		Compress:   true,                 // Compress old log files
	}

	log.Println("ConfigureServiceLogging::defineHandler")

	// Create a slog handler that writes to the Lumberjack rotator
	handler := slog.NewJSONHandler(logRotator, &slog.HandlerOptions{
		AddSource: true, // Add source file and line number to logs
		Level:     slog.LevelInfo,
	})

	log.Println("ConfigureServiceLogging::new_slog")
	logger := slog.New(handler)

	log.Println("ConfigureServiceLogging::setDefault")
	slog.SetDefault(logger)

	log.Println("ConfigureServiceLogging::end")
}

func main() {
	log.Println("Starting Application")
	ConfigureServiceLogging()
	log.Println("Stopping Application")
}

What did you see happen?

When I attempt to run this application it dies without a panic when attempting to SetDefault. Here is the output when I run ./main.exe from an interactive shell.

/ # ./main.exe                                                                                                                                   
2025/10/04 17:14:21 Starting Application
2025/10/04 17:14:21 ConfigureServiceLogging::start                                                                                               
2025/10/04 17:14:21 ConfigureServiceLogging::defineRotator
2025/10/04 17:14:21 ConfigureServiceLogging::defineHandler                                                                                       
2025/10/04 17:14:21 ConfigureServiceLogging::new_slog
2025/10/04 17:14:21 ConfigureServiceLogging::setDefault
/ # echo $?
0                                                                                          
/ # 

As you can clearly see, there are two log lines that never execute, nor would any other code.
The application has an exit code of 0. Quite odd.

What did you expect to see?

I expected to see all log lines including the two missing ones to appear. Setting the default is supposed to allow for log.Printf or whatever function call is already there to continue to work but be brought into the slog configuration.

I even tried changing those last two log lines to slog.Info(...) and they continue to be missing from the logging output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions