Debian Codegraph @

src/runtime/testdata/testgoroutineleakprofile/goker/cockroach18101.go

raw
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a MIT
3 // license that can be found in the LICENSE file.
4
5 /*
6 * Project: cockroach
7 * Issue or PR : https://github.com/cockroachdb/cockroach/pull/18101
8 * Buggy version: f7a8e2f57b6bcf00b9abaf3da00598e4acd3a57f
9 * fix commit-id: 822bd176cc725c6b50905ea615023200b395e14f
10 * Flaky: 100/100
11 */
12
13 package main
14
15 import (
16 "context"
17 "os"
18 "runtime/pprof"
19 "time"
20 )
21
22 func init() {
23 register("Cockroach18101", Cockroach18101)
24 }
25
26 const chanSize_cockroach18101 = 6
27
28 func restore_cockroach18101(ctx context.Context) bool {
29 readyForImportCh := make(chan bool, chanSize_cockroach18101)
30 go func() { // G2
31 defer close(readyForImportCh)
32 splitAndScatter_cockroach18101(ctx, readyForImportCh)
33 }()
34 for readyForImportSpan := range readyForImportCh {
35 select {
36 case <-ctx.Done():
37 return readyForImportSpan
38 }
39 }
40 return true
41 }
42
43 func splitAndScatter_cockroach18101(ctx context.Context, readyForImportCh chan bool) {
44 for i := 0; i < chanSize_cockroach18101+2; i++ {
45 readyForImportCh <- (false || i != 0)
46 }
47 }
48
49 func Cockroach18101() {
50 prof := pprof.Lookup("goroutineleak")
51 defer func() {
52 time.Sleep(100 * time.Millisecond)
53 prof.WriteTo(os.Stdout, 2)
54 }()
55 for i := 0; i < 100; i++ {
56 ctx, cancel := context.WithCancel(context.Background())
57 go restore_cockroach18101(ctx) // G1
58 go cancel() // helper goroutine
59 }
60 }