Skip to content

Conversation

CertiK-Geth
Copy link

What does this pull request do? Explain your changes. (required)
This PR is intended to fix the potential goroutine leak issue. In the StartLivepeer function, there is a potential goroutine leak caused by sending to an un-buffered channel. The channels ec, tc, and wc are un-buffered, which can lead to a situation where the goroutine blocks indefinitely if the ctx.Done() branch wins the race. This results in leaked resources as the goroutine is never able to complete its execution.

func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
    //...
	ec := make(chan error)
	tc := make(chan struct{})
	wc := make(chan struct{})
	//...
	select {
		case err := <-ec:
			glog.Infof("Error from media server: %v", err)
			return
		case <-tc:
			glog.Infof("Orchestrator server shut down")
		case <-wc:
			glog.Infof("CLI webserver shut down")
			return
		case <-ctx.Done():
			srv.Shutdown(ctx)
			return
	}
}

The same issue exists in the getOrchestratorInfo function from server/router.go, where an un-buffered channel infoCh is used to receive orchestrator information

Specific updates (required)
To prevent the potential goroutine leak, this PR make the channels buffered by specifying a buffer size of 1.

How did you test each of these updates (required)

Does this pull request close any open issues?
No

Checklist:

@github-actions github-actions bot added the go Pull requests that update Go code label Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant