File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -15,21 +15,32 @@ import (
15
15
"runtime"
16
16
"strconv"
17
17
"sync"
18
+ "sync/atomic"
18
19
)
19
20
20
21
var DebugGoroutines = os .Getenv ("DEBUG_HTTP2_GOROUTINES" ) == "1"
21
22
23
+ // Setting DebugGoroutines to false during a test to disable goroutine debugging
24
+ // results in race detector complaints when a test leaves goroutines running before
25
+ // returning. Tests shouldn't do this, of course, but when they do it generally shows
26
+ // up as infrequent, hard-to-debug flakes. (See #66519.)
27
+ //
28
+ // Disable goroutine debugging during individual tests with an atomic bool.
29
+ // (Note that it's safe to enable/disable debugging mid-test, so the actual race condition
30
+ // here is harmless.)
31
+ var disableDebugGoroutines atomic.Bool
32
+
22
33
type goroutineLock uint64
23
34
24
35
func newGoroutineLock () goroutineLock {
25
- if ! DebugGoroutines {
36
+ if ! DebugGoroutines || disableDebugGoroutines . Load () {
26
37
return 0
27
38
}
28
39
return goroutineLock (curGoroutineID ())
29
40
}
30
41
31
42
func (g goroutineLock ) check () {
32
- if ! DebugGoroutines {
43
+ if ! DebugGoroutines || disableDebugGoroutines . Load () {
33
44
return
34
45
}
35
46
if curGoroutineID () != uint64 (g ) {
@@ -38,7 +49,7 @@ func (g goroutineLock) check() {
38
49
}
39
50
40
51
func (g goroutineLock ) checkNotOn () {
41
- if ! DebugGoroutines {
52
+ if ! DebugGoroutines || disableDebugGoroutines . Load () {
42
53
return
43
54
}
44
55
if curGoroutineID () == uint64 (g ) {
Original file line number Diff line number Diff line change @@ -3520,9 +3520,10 @@ func testServerContentLengthCanBeDisabled(t testing.TB) {
3520
3520
}
3521
3521
3522
3522
func disableGoroutineTracking (t testing.TB ) {
3523
- old := DebugGoroutines
3524
- DebugGoroutines = false
3525
- t .Cleanup (func () { DebugGoroutines = old })
3523
+ disableDebugGoroutines .Store (true )
3524
+ t .Cleanup (func () {
3525
+ disableDebugGoroutines .Store (false )
3526
+ })
3526
3527
}
3527
3528
3528
3529
func BenchmarkServer_GetRequest (b * testing.B ) {
You can’t perform that action at this time.
0 commit comments