Skip to content

A potential goroutine leak in orca/producer_test.go #8891

@user12031

Description

@user12031

If the case <-ctx.Done(): is selected

select {
case req := <-fake.reqCh:
if got := req.GetReportInterval().AsDuration(); got != interval {
t.Errorf("Unexpected report interval; got %v want %v", got, interval)
}
case <-ctx.Done():
t.Fatalf("Did not receive client request")
}

There is no chan receive operation to awaken f.reqCh <- req, which results in a goroutine leak.

f.reqCh <- req

How to reproduce:
Add time.Sleep(time.Second) before f.reqCh <- req , which makes case <-ctx.Done(): is selected.

time.Sleep(time.Second)
f.reqCh <- req

Then using goleak to detect the goroutine leak in the test function .

func (s) TestProducerBackoff(t *testing.T) {

The bug report is as follow:

found unexpected goroutines:
        [Goroutine 26 in state chan send, with google.golang.org/grpc/orca_test.(*fakeORCAService).StreamCoreMetrics on top of the stack:
        goroutine 26 [chan send]:
        google.golang.org/grpc/orca_test.(*fakeORCAService).StreamCoreMetrics(0xc00025a350, 0xc0003a05f0, {0xbb4cb0, 0xc000113230})
        	/home/song2048/桌面/goProject/src/SOSFuzz/testdata/grpc-go/orca/producer_test.go:239 +0x91
        github.com/cncf/xds/go/xds/service/orca/v3._OpenRcaService_StreamCoreMetrics_Handler({0xa024a0?, 0xc00025a350}, {0xbb3c90, 0xc0001225a0})
        	/home/song2048/桌面/goProject/pkg/mod/github.com/cncf/xds/go@v0.0.0-20231128003011-0fa0005c9caa/xds/service/orca/v3/orca.pb.go:265 +0xd0
        google.golang.org/grpc.(*Server).processStreamingRPC(0xc0000f8fc0, {0xbb2700, 0xc00012bef0}, {0xbb5cd8, 0xc0003161a0}, 0xc00016ab40, 0xc0001c9b30, 0xf8c420, 0x0)
        	/home/song2048/桌面/goProject/src/SOSFuzz/testdata/grpc-go/server.go:1709 +0x12e4
        google.golang.org/grpc.(*Server).handleStream(0xc0000f8fc0, {0xbb5cd8, 0xc0003161a0}, 0xc00016ab40)
        	/home/song2048/桌面/goProject/src/SOSFuzz/testdata/grpc-go/server.go:1834 +0xd3a
        google.golang.org/grpc.(*Server).serveStreams.func2.1()
        	/home/song2048/桌面/goProject/src/SOSFuzz/testdata/grpc-go/server.go:1053 +0x88
        created by google.golang.org/grpc.(*Server).serveStreams.func2
        	/home/song2048/桌面/goProject/src/SOSFuzz/testdata/grpc-go/server.go:1064 +0x165
        ]
--- FAIL: TestProducerBackoff_1 (5.46s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions