Introduction
Go’s emphasis on backwards compatibility is one of its key strengths. However, there are times when we cannot maintain complete compatibility. If code depends on buggy (including insecure) behavior, then fixing the bug will break that code.key=value pair that controls the execution of certain parts of a Go program. The environment variable GODEBUG can hold a comma-separated list of these settings.
Basic Usage
If a Go program is running in an environment that contains:GODEBUG environment variable are ignored.Setting GODEBUG
- Command line
- Shell export
- Go source
Default GODEBUG Values
When a GODEBUG setting is not listed in the environment variable, its value is derived from three sources:Example: panicnil Setting
Go 1.21 introduces thepanicnil setting, controlling whether panic(nil) is allowed. It defaults to panicnil=0, making panic(nil) a run-time error.
When a Go 1.21 toolchain compiles a program, if the work module’s go.mod says go 1.20, then the program defaults to panicnil=1, matching Go 1.20 instead of Go 1.21.
Using godebug Directives
Starting in Go 1.23, the work module’sgo.mod or workspace’s go.work can list one or more godebug lines:
default indicates a Go version to take unspecified settings from. This allows setting the GODEBUG defaults separately from the Go language version in the module.Using //go:debug Directives
Starting in Go 1.21, a main package’s source files can include one or more//go:debug directives at the top of the file:
Runtime Metrics
When possible, each GODEBUG setting has an associated runtime/metrics counter named/godebug/non-default-behavior/<name>:events that counts the number of times a particular program’s behavior has changed based on a non-default value.
For example, when GODEBUG=http2client=0 is set, /godebug/non-default-behavior/http2client:events counts the number of HTTP transports that the program has configured without HTTP/2 support.
GODEBUG History
GODEBUG settings are introduced when behavior changes and maintained for a minimum of two years (four Go releases). Some settings are maintained much longer or indefinitely.Go 1.27
Go 1.27 removed thegotypesalias setting.
Go 1.26
httpcookiemaxnum - Cookie parsing limit
httpcookiemaxnum - Cookie parsing limit
urlmaxqueryparams - Query parameter limit
urlmaxqueryparams - Query parameter limit
net/url will accept.- Default:
urlmaxqueryparams=10000 - Setting to
0disables the limit - Backported to Go 1.25.6 and Go 1.24.12
urlstrictcolons - URL hostname validation
urlstrictcolons - URL hostname validation
net/url.Parse allows malformed hostnames containing colons.- Default:
urlstrictcolons=1(rejectshttp://localhost:1:2) - Colons permitted in bracketed IPv6 addresses like
http://[::1]/
tlssecpmlkem - Post-quantum TLS
tlssecpmlkem - Post-quantum TLS
- Default: Enabled
- Revert with
tlssecpmlkem=0
tracebacklabels - Goroutine labels
tracebacklabels - Goroutine labels
runtime/pprof in tracebacks.- Default:
tracebacklabels=0 - Enable with
tracebacklabels=1
cryptocustomrand - Crypto random source
cryptocustomrand - Crypto random source
crypto/* APIs ignore the random io.Reader parameter.- Default:
cryptocustomrand=0(ignores random parameters) - Use
cryptocustomrand=1for pre-Go 1.26 behavior
Go 1.25
decoratemappings - Memory mapping annotations
decoratemappings - Memory mapping annotations
- Default:
decoratemappings=1 - Annotations appear in
/proc/self/mapsas “[anon: Go: …]” - Fixed at program startup time
embedfollowsymlinks - Embed symlink behavior
embedfollowsymlinks - Embed symlink behavior
- Default:
embedfollowsymlinks=0(don’t follow) - Use
embedfollowsymlinks=1to follow symlinks
containermaxprocs - Container CPU limits
containermaxprocs - Container CPU limits
- Default:
containermaxprocs=1(use cgroup limits) - Set to
0to disable
updatemaxprocs - Dynamic GOMAXPROCS
updatemaxprocs - Dynamic GOMAXPROCS
- Default:
updatemaxprocs=1(enable periodic updates) - Set to
0to disable
tlssha1 - SHA-1 in TLS
tlssha1 - SHA-1 in TLS
- Default: SHA-1 disabled
- Use
tlssha1=1to revert
x509sha256skid - Certificate SubjectKeyId
x509sha256skid - Certificate SubjectKeyId
crypto/x509.CreateCertificate.- Default: SHA-256
- Use
x509sha256skid=0to revert to SHA-1
allowmultiplevcs - Multiple VCS security
allowmultiplevcs - Multiple VCS security
- Default: Disabled
- Use
allowmultiplevcs=1to re-enable - Backported to Go 1.24.5 and Go 1.23.11
Go 1.24
fips140 - FIPS 140-3 mode
fips140 - FIPS 140-3 mode
"off": No FIPS 140-3 support (default)"on": FIPS 140-3 mode enabled"only": Like “on”, but non-approved algorithms return errors- Fixed at program startup time
randseednop - math/rand.Seed behavior
randseednop - math/rand.Seed behavior
math/rand.Seed to be a no-op.- Default:
randseednop=1(no-op) - Use
randseednop=0for pre-Go 1.24 behavior
multipathtcp - Multipath TCP
multipathtcp - Multipath TCP
"0": Disable MPTCP on dialers and listeners"1": Enable MPTCP on dialers and listeners"2": Enable MPTCP on listeners only (default for Go 1.24)"3": Enable MPTCP on dialers only
gotestjsonbuildtext - Test JSON output
gotestjsonbuildtext - Test JSON output
go test -json to emit build errors as JSON.- Default: JSON format
- Use
gotestjsonbuildtext=1for Go 1.23 text format - Will be removed in Go 1.28 at the earliest
rsa1024min - Minimum RSA key size
rsa1024min - Minimum RSA key size
- Default: 1024-bit minimum
- Use
rsa1024min=0for Go 1.23 behavior
dataindependenttiming - Data Independent Timing
dataindependenttiming - Data Independent Timing
- Default:
dataindependenttiming=0 - Use
dataindependenttiming=1to enable
tlsmlkem - Post-quantum TLS (X25519MLKEM768)
tlsmlkem - Post-quantum TLS (X25519MLKEM768)
- Default: Enabled
- Use
tlsmlkem=0to disable (useful for buggy TLS servers)
x509rsacrt - RSA CRT parameters
x509rsacrt - RSA CRT parameters
ParsePKCS1PrivateKey use and validate CRT parameters.- Default: Validate CRT parameters
- Use
x509rsacrt=0for Go 1.23 behavior
Go 1.23
asynctimerchan - Timer channels
asynctimerchan - Timer channels
- Default: Unbuffered channels
- Use
asynctimerchan=1for buffered channels - Will be removed in Go 1.27
winsymlink - Windows symlink mode bits
winsymlink - Windows symlink mode bits
os.Lstat and os.Stat for reparse points (Windows only).- Default:
winsymlink=1 - Mount points no longer have
os.ModeSymlinkset
winreadlinkvolume - Windows volume normalization
winreadlinkvolume - Windows volume normalization
os.Readlink and filepath.EvalSymlinks to avoid normalizing volumes to drive letters.- Default:
winreadlinkvolume=1
tls3des - 3DES cipher suites
tls3des - 3DES cipher suites
- Default: 3DES disabled
- Use
tls3des=1to revert - Will be removed in Go 1.27
x509keypairleaf - TLS Certificate Leaf field
x509keypairleaf - TLS Certificate Leaf field
tls.X509KeyPair and tls.LoadX509KeyPair to populate the Leaf field.- Default:
x509keypairleaf=1 - Will be removed in Go 1.27
Go 1.22
tlsmaxrsasize - Maximum RSA key size in TLS
tlsmaxrsasize - Maximum RSA key size in TLS
- Default:
tlsmaxrsasize=8192 - Backported to Go 1.19.13, 1.20.8, and 1.21.1
httplaxcontentlength - Empty Content-Length
httplaxcontentlength - Empty Content-Length
- Default: Strict validation
- Use
httplaxcontentlength=1to allow empty headers
httpmuxgo121 - ServeMux pattern matching
httpmuxgo121 - ServeMux pattern matching
- Default: New behavior
- Use
httpmuxgo121=1for Go 1.21 behavior
gotypesalias - Type aliases in go/types
gotypesalias - Type aliases in go/types
- Go 1.22 default:
gotypesalias=0 - Go 1.23+ default:
gotypesalias=1 - Removed in Go 1.27
tls10server - Minimum TLS version
tls10server - Minimum TLS version
- Default: TLS 1.2 minimum
- Use
tls10server=1to revert to TLS 1.0 - Will be removed in Go 1.27
disablethp - Transparent huge pages
disablethp - Transparent huge pages
- Use
disablethp=1to disable THP for Go memory - Available starting Go 1.21.6
- May be removed in future release
Go 1.21 and Earlier
panicnil - panic(nil) behavior (Go 1.21)
panicnil - panic(nil) behavior (Go 1.21)
panic with a nil interface value.- Default: Error on
panic(nil) - No plan to remove this setting
multipathtcp - Multipath TCP support (Go 1.21)
multipathtcp - Multipath TCP support (Go 1.21)
- Default: Disabled unless explicitly requested
- No plan to remove this setting
randautoseed - math/rand auto-seeding (Go 1.20)
randautoseed - math/rand auto-seeding (Go 1.20)
math/rand generator.- Default: Auto-seed enabled
- No plan to remove this setting
execerrdot - Path lookup in current directory (Go 1.19)
execerrdot - Path lookup in current directory (Go 1.19)
- Default: Error on current directory lookups
- No plan to remove this setting
http2client/http2server - HTTP/2 support (Go 1.6)
http2client/http2server - HTTP/2 support (Go 1.6)
- Default: HTTP/2 enabled
- Set to
0to disable - No plan to remove these settings
netdns - DNS resolver (Go 1.5)
netdns - DNS resolver (Go 1.5)
- Platform-dependent default
- No plan to remove this setting