ApplicationInsights-Go icon indicating copy to clipboard operation
ApplicationInsights-Go copied to clipboard

goroutine leak detected in throttleManager.Stop

Open crobert-1 opened this issue 1 year ago • 0 comments

I'm working on enabling goleak checks in another project (context here: https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/30438), and a leak has been detected in this package.

Goleak output:

goleak: Errors on successful test run: found unexpected goroutines:
[Goroutine 26 in state chan receive, with github.com/microsoft/ApplicationInsights-Go/appinsights.(*throttleManager).Stop on top of the stack:
github.com/microsoft/ApplicationInsights-Go/appinsights.(*throttleManager).Stop(0xc000136768)
	/Users/crobert/go/pkg/mod/github.com/microsoft/[email protected]/appinsights/throttle.go:65 +0xdf
github.com/microsoft/ApplicationInsights-Go/appinsights.(*inMemoryChannelState).stop(0xc0003aa050)
	/Users/crobert/go/pkg/mod/github.com/microsoft/[email protected]/appinsights/inmemorychannel.go:360 +0xd8
github.com/microsoft/ApplicationInsights-Go/appinsights.(*InMemoryChannel).acceptLoop(0xc0004069c0)
	/Users/crobert/go/pkg/mod/github.com/microsoft/[email protected]/appinsights/inmemorychannel.go:149 +0x46
created by github.com/microsoft/ApplicationInsights-Go/appinsights.NewInMemoryChannel in goroutine 24
	/Users/crobert/go/pkg/mod/github.com/microsoft/[email protected]/appinsights/inmemorychannel.go:59 +0x2a5
]

From what I can tell, throttleManager.Stop() is blocking while waiting for a message to be sent on the result channel. However, in the problem method waitForThrottle(), the other running goroutine does not send a message to msg.result when the message with stop: true is sent to the msg channel. This means the stop operation is sent successfully, but since there's nothing sent to the result channel, it blocks forever in Stop().

crobert-1 avatar Jan 26 '24 18:01 crobert-1