2023-03-14 14:25:56 -04:00
|
|
|
// Copyright 2023 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// Package godebugs provides a table of known GODEBUG settings,
|
|
|
|
|
// for use by a variety of other packages, including internal/godebug,
|
|
|
|
|
// runtime, runtime/metrics, and cmd/go/internal/load.
|
|
|
|
|
package godebugs
|
|
|
|
|
|
|
|
|
|
// An Info describes a single known GODEBUG setting.
|
|
|
|
|
type Info struct {
|
|
|
|
|
Name string // name of the setting ("panicnil")
|
|
|
|
|
Package string // package that uses the setting ("runtime")
|
|
|
|
|
Changed int // minor version when default changed, if any; 21 means Go 1.21
|
|
|
|
|
Old string // value that restores behavior prior to Changed
|
|
|
|
|
Opaque bool // setting does not export information to runtime/metrics using [internal/godebug.Setting.IncNonDefault]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All is the table of known settings, sorted by Name.
|
|
|
|
|
//
|
|
|
|
|
// Note: After adding entries to this table, run 'go generate runtime/metrics'
|
|
|
|
|
// to update the runtime/metrics doc comment.
|
|
|
|
|
// (Otherwise the runtime/metrics test will fail.)
|
|
|
|
|
//
|
|
|
|
|
// Note: After adding entries to this table, update the list in doc/godebug.md as well.
|
|
|
|
|
// (Otherwise the test in this package will fail.)
|
|
|
|
|
var All = []Info{
|
time: garbage collect unstopped Tickers and Timers
From the beginning of Go, the time package has had a gotcha:
if you use a select on <-time.After(1*time.Minute), even if the select
finishes immediately because some other case is ready, the underlying
timer from time.After keeps running until the minute is over. This
pins the timer in the timer heap, which keeps it from being garbage
collected and in extreme cases also slows down timer operations.
The lack of garbage collection is the more important problem.
The docs for After warn against this scenario and suggest using
NewTimer with a call to Stop after the select instead, purely to work
around this garbage collection problem.
Oddly, the docs for NewTimer and NewTicker do not mention this
problem, but they have the same issue: they cannot be collected until
either they are Stopped or, in the case of Timer, the timer expires.
(Tickers repeat, so they never expire.) People have built up a shared
knowledge that timers and tickers need to defer t.Stop even though the
docs do not mention this (it is somewhat implied by the After docs).
This CL fixes the garbage collection problem, so that a timer that is
unreferenced can be GC'ed immediately, even if it is still running.
The approach is to only insert the timer into the heap when some
channel operation is blocked on it; the last channel operation to stop
using the timer takes it back out of the heap. When a timer's channel
is no longer referenced, there are no channel operations blocked on
it, so it's not in the heap, so it can be GC'ed immediately.
This CL adds an undocumented GODEBUG asynctimerchan=1
that will disable the change. The documentation happens in
the CL 568341.
Fixes #8898.
Fixes #61542.
Change-Id: Ieb303b6de1fb3527d3256135151a9e983f3c27e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/512355
Reviewed-by: Austin Clements <austin@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Russ Cox <rsc@golang.org>
2024-02-14 20:36:47 -05:00
|
|
|
{Name: "asynctimerchan", Package: "time", Opaque: true},
|
2023-03-14 14:25:56 -04:00
|
|
|
{Name: "execerrdot", Package: "os/exec"},
|
2023-04-21 19:55:43 -07:00
|
|
|
{Name: "gocachehash", Package: "cmd/go"},
|
|
|
|
|
{Name: "gocachetest", Package: "cmd/go"},
|
|
|
|
|
{Name: "gocacheverify", Package: "cmd/go"},
|
2024-03-08 21:01:17 -05:00
|
|
|
{Name: "gotypesalias", Package: "go/types", Opaque: true}, // bug #66216: remove Opaque
|
2023-03-14 14:25:56 -04:00
|
|
|
{Name: "http2client", Package: "net/http"},
|
|
|
|
|
{Name: "http2debug", Package: "net/http", Opaque: true},
|
|
|
|
|
{Name: "http2server", Package: "net/http"},
|
2023-08-10 20:56:27 +00:00
|
|
|
{Name: "httplaxcontentlength", Package: "net/http", Changed: 22, Old: "1"},
|
2023-09-23 17:05:42 -04:00
|
|
|
{Name: "httpmuxgo121", Package: "net/http", Changed: 22, Old: "1"},
|
2023-03-14 14:25:56 -04:00
|
|
|
{Name: "installgoroot", Package: "go/build"},
|
2024-03-08 21:01:17 -05:00
|
|
|
{Name: "jstmpllitinterp", Package: "html/template", Opaque: true}, // bug #66217: remove Opaque
|
2023-03-14 14:25:56 -04:00
|
|
|
//{Name: "multipartfiles", Package: "mime/multipart"},
|
|
|
|
|
{Name: "multipartmaxheaders", Package: "mime/multipart"},
|
|
|
|
|
{Name: "multipartmaxparts", Package: "mime/multipart"},
|
2023-06-30 17:24:57 +02:00
|
|
|
{Name: "multipathtcp", Package: "net"},
|
2023-03-14 14:25:56 -04:00
|
|
|
{Name: "netdns", Package: "net", Opaque: true},
|
|
|
|
|
{Name: "panicnil", Package: "runtime", Changed: 21, Old: "1"},
|
|
|
|
|
{Name: "randautoseed", Package: "math/rand"},
|
|
|
|
|
{Name: "tarinsecurepath", Package: "archive/tar"},
|
2023-11-10 10:12:48 -08:00
|
|
|
{Name: "tls10server", Package: "crypto/tls", Changed: 22, Old: "1"},
|
2023-08-08 18:25:59 -07:00
|
|
|
{Name: "tlsmaxrsasize", Package: "crypto/tls"},
|
2023-11-10 10:42:42 -08:00
|
|
|
{Name: "tlsrsakex", Package: "crypto/tls", Changed: 22, Old: "1"},
|
2023-11-21 16:37:07 +01:00
|
|
|
{Name: "tlsunsafeekm", Package: "crypto/tls", Changed: 22, Old: "1"},
|
2024-03-11 18:16:16 +01:00
|
|
|
{Name: "winreadlinkvolume", Package: "os", Changed: 22, Old: "0"},
|
|
|
|
|
{Name: "winsymlink", Package: "os", Changed: 22, Old: "0"},
|
2023-03-14 14:25:56 -04:00
|
|
|
{Name: "x509sha1", Package: "crypto/x509"},
|
|
|
|
|
{Name: "x509usefallbackroots", Package: "crypto/x509"},
|
2023-12-04 10:17:34 -08:00
|
|
|
{Name: "x509usepolicies", Package: "crypto/x509"},
|
2023-03-14 14:25:56 -04:00
|
|
|
{Name: "zipinsecurepath", Package: "archive/zip"},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lookup returns the Info with the given name.
|
|
|
|
|
func Lookup(name string) *Info {
|
|
|
|
|
// binary search, avoiding import of sort.
|
|
|
|
|
lo := 0
|
|
|
|
|
hi := len(All)
|
|
|
|
|
for lo < hi {
|
2023-09-12 13:18:33 +00:00
|
|
|
m := int(uint(lo+hi) >> 1)
|
2023-03-14 14:25:56 -04:00
|
|
|
mid := All[m].Name
|
|
|
|
|
if name == mid {
|
|
|
|
|
return &All[m]
|
|
|
|
|
}
|
|
|
|
|
if name < mid {
|
|
|
|
|
hi = m
|
|
|
|
|
} else {
|
|
|
|
|
lo = m + 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|