Debian Codegraph @

src/runtime/testdata/testgoroutineleakprofile/goker/cockroach13755.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/13755
8 * Buggy version: 7acb881bbb8f23e87b69fce9568d9a3316b5259c
9 * fix commit-id: ef906076adc1d0e3721944829cfedfed51810088
10 * Flaky: 100/100
11 */
12
13 package main
14
15 import (
16 "context"
17 "os"
18 "runtime"
19 "runtime/pprof"
20 )
21
22 func init() {
23 register("Cockroach13755", Cockroach13755)
24 }
25
26 type Rows_cockroach13755 struct {
27 cancel context.CancelFunc
28 }
29
30 func (rs *Rows_cockroach13755) initContextClose(ctx context.Context) {
31 ctx, rs.cancel = context.WithCancel(ctx)
32 go rs.awaitDone(ctx)
33 }
34
35 func (rs *Rows_cockroach13755) awaitDone(ctx context.Context) {
36 <-ctx.Done()
37 rs.close(ctx.Err())
38 }
39
40 func (rs *Rows_cockroach13755) close(err error) {
41 rs.cancel()
42 }
43
44 // Example of goroutine leak trace:
45 //
46 // G1 G2
47 //----------------------------------------
48 // initContextClose()
49 // . awaitDone()
50 // <<done>> .
51 // <-tx.ctx.Done()
52 //----------------G2 leak-----------------
53
54 func Cockroach13755() {
55 prof := pprof.Lookup("goroutineleak")
56 defer func() {
57 // Yield several times to allow the child goroutine to run.
58 for i := 0; i < yieldCount; i++ {
59 runtime.Gosched()
60 }
61 prof.WriteTo(os.Stdout, 2)
62 }()
63
64 rs := &Rows_cockroach13755{}
65 rs.initContextClose(context.Background())
66 }