Source file src/runtime/testdata/testgoroutineleakprofile/goker/kubernetes25331.go

     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: kubernetes
     7   * Issue or PR  : https://github.com/kubernetes/kubernetes/pull/25331
     8   * Buggy version: 5dd087040bb13434f1ddf2f0693d0203c30f28cb
     9   * fix commit-id: 97f4647dc3d8cf46c2b66b89a31c758a6edfb57c
    10   * Flaky: 100/100
    11   */
    12  package main
    13  
    14  import (
    15  	"context"
    16  	"errors"
    17  	"os"
    18  	"runtime"
    19  	"runtime/pprof"
    20  )
    21  
    22  func init() {
    23  	register("Kubernetes25331", Kubernetes25331)
    24  }
    25  
    26  type watchChan_kubernetes25331 struct {
    27  	ctx        context.Context
    28  	cancel     context.CancelFunc
    29  	resultChan chan bool
    30  	errChan    chan error
    31  }
    32  
    33  func (wc *watchChan_kubernetes25331) Stop() {
    34  	wc.errChan <- errors.New("Error")
    35  	wc.cancel()
    36  }
    37  
    38  func (wc *watchChan_kubernetes25331) run() {
    39  	select {
    40  	case err := <-wc.errChan:
    41  		errResult := len(err.Error()) != 0
    42  		wc.cancel() // Removed in fix
    43  		wc.resultChan <- errResult
    44  	case <-wc.ctx.Done():
    45  	}
    46  }
    47  
    48  func NewWatchChan_kubernetes25331() *watchChan_kubernetes25331 {
    49  	ctx, cancel := context.WithCancel(context.Background())
    50  	return &watchChan_kubernetes25331{
    51  		ctx:        ctx,
    52  		cancel:     cancel,
    53  		resultChan: make(chan bool),
    54  		errChan:    make(chan error),
    55  	}
    56  }
    57  
    58  func Kubernetes25331() {
    59  	prof := pprof.Lookup("goroutineleak")
    60  	defer func() {
    61  		// Yield several times to allow the child goroutine to run.
    62  		for i := 0; i < yieldCount; i++ {
    63  			runtime.Gosched()
    64  		}
    65  		prof.WriteTo(os.Stdout, 2)
    66  	}()
    67  	go func() {
    68  		wc := NewWatchChan_kubernetes25331()
    69  		go wc.run()  // G1
    70  		go wc.Stop() // G2
    71  	}()
    72  }
    73  

View as plain text