Source file src/runtime/testdata/testgoroutineleakprofile/goker/moby7559.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: moby
     7   * Issue or PR  : https://github.com/moby/moby/pull/7559
     8   * Buggy version: 64579f51fcb439c36377c0068ccc9a007b368b5a
     9   * fix commit-id: 6cbb8e070d6c3a66bf48fbe5cbf689557eee23db
    10   * Flaky: 100/100
    11   */
    12  package main
    13  
    14  import (
    15  	"net"
    16  	"os"
    17  	"runtime/pprof"
    18  	"sync"
    19  	"time"
    20  )
    21  
    22  func init() {
    23  	register("Moby7559", Moby7559)
    24  }
    25  
    26  type UDPProxy_moby7559 struct {
    27  	connTrackLock sync.Mutex
    28  }
    29  
    30  func (proxy *UDPProxy_moby7559) Run() {
    31  	for i := 0; i < 2; i++ {
    32  		proxy.connTrackLock.Lock()
    33  		_, err := net.DialUDP("udp", nil, nil)
    34  		if err != nil {
    35  			continue
    36  			/// Missing unlock here
    37  		}
    38  		if i == 0 {
    39  			break
    40  		}
    41  	}
    42  	proxy.connTrackLock.Unlock()
    43  }
    44  
    45  func Moby7559() {
    46  	prof := pprof.Lookup("goroutineleak")
    47  	defer func() {
    48  		time.Sleep(100 * time.Millisecond)
    49  		prof.WriteTo(os.Stdout, 2)
    50  	}()
    51  
    52  	for i := 0; i < 20; i++ {
    53  		go (&UDPProxy_moby7559{}).Run()
    54  	}
    55  }
    56  

View as plain text