Debian Codegraph @

src/runtime/testdata/testgoroutineleakprofile/goker/etcd6857.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: etcd
7 * Issue or PR : https://github.com/etcd-io/etcd/pull/6857
8 * Buggy version: 7c8f13aed7fe251e7066ed6fc1a090699c2cae0e
9 * fix commit-id: 7afc490c95789c408fbc256d8e790273d331c984
10 * Flaky: 19/100
11 */
12 package main
13
14 import (
15 "os"
16 "runtime/pprof"
17 "time"
18 )
19
20 func init() {
21 register("Etcd6857", Etcd6857)
22 }
23
24 type Status_etcd6857 struct{}
25
26 type node_etcd6857 struct {
27 status chan chan Status_etcd6857
28 stop chan struct{}
29 done chan struct{}
30 }
31
32 func (n *node_etcd6857) Status() Status_etcd6857 {
33 c := make(chan Status_etcd6857)
34 n.status <- c
35 return <-c
36 }
37
38 func (n *node_etcd6857) run() {
39 for {
40 select {
41 case c := <-n.status:
42 c <- Status_etcd6857{}
43 case <-n.stop:
44 close(n.done)
45 return
46 }
47 }
48 }
49
50 func (n *node_etcd6857) Stop() {
51 select {
52 case n.stop <- struct{}{}:
53 case <-n.done:
54 return
55 }
56 <-n.done
57 }
58
59 func NewNode_etcd6857() *node_etcd6857 {
60 return &node_etcd6857{
61 status: make(chan chan Status_etcd6857),
62 stop: make(chan struct{}),
63 done: make(chan struct{}),
64 }
65 }
66
67 func Etcd6857() {
68 prof := pprof.Lookup("goroutineleak")
69 defer func() {
70 time.Sleep(100 * time.Millisecond)
71 prof.WriteTo(os.Stdout, 2)
72 }()
73 for i := 0; i <= 100; i++ {
74 go func() {
75 n := NewNode_etcd6857()
76 go n.run() // G1
77 go n.Status() // G2
78 go n.Stop() // G3
79 }()
80 }
81 }