Debian Codegraph @

src/runtime/testdata/testgoroutineleakprofile/goker/etcd10492.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 package main
6
7 import (
8 "context"
9 "os"
10 "runtime"
11 "runtime/pprof"
12 "sync"
13 "time"
14 )
15
16 func init() {
17 register("Etcd10492", Etcd10492)
18 }
19
20 type Checkpointer_etcd10492 func(ctx context.Context)
21
22 type lessor_etcd10492 struct {
23 mu sync.RWMutex
24 cp Checkpointer_etcd10492
25 checkpointInterval time.Duration
26 }
27
28 func (le *lessor_etcd10492) Checkpoint() {
29 le.mu.Lock() // Lock acquired twice here
30 defer le.mu.Unlock()
31 }
32
33 func (le *lessor_etcd10492) SetCheckpointer(cp Checkpointer_etcd10492) {
34 le.mu.Lock()
35 defer le.mu.Unlock()
36
37 le.cp = cp
38 }
39
40 func (le *lessor_etcd10492) Renew() {
41 le.mu.Lock()
42 unlock := func() { le.mu.Unlock() }
43 defer func() { unlock() }()
44
45 if le.cp != nil {
46 le.cp(context.Background())
47 }
48 }
49
50 func Etcd10492() {
51 prof := pprof.Lookup("goroutineleak")
52 defer func() {
53 // Yield several times to allow the child goroutine to run.
54 for i := 0; i < yieldCount; i++ {
55 runtime.Gosched()
56 }
57 prof.WriteTo(os.Stdout, 2)
58 }()
59
60 go func() { // G1
61 le := &lessor_etcd10492{
62 checkpointInterval: 0,
63 }
64 fakerCheckerpointer_etcd10492 := func(ctx context.Context) {
65 le.Checkpoint()
66 }
67 le.SetCheckpointer(fakerCheckerpointer_etcd10492)
68 le.mu.Lock()
69 le.mu.Unlock()
70 le.Renew()
71 }()
72 }