Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.4-stable] pillar/devicenetwork: fix goroutine leak #4425

Conversation

christoph-zededa
Copy link
Contributor

introduced in 8573372

without this fix, the goroutine is blocked by trying to send into a channel that has no receiver

Signed-off-by: Christoph Ostarek christoph@zededa.com
(cherry picked from commit d93cf8b)

introduced in 8573372

without this fix, the goroutine is blocked by trying to send
into a channel that has no receiver

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
(cherry picked from commit d93cf8b)
resolvedIPsChan <- response
if response != nil && len(response) > 0 {
select {
case resolvedIPsChan <- response:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't check your latest changes before they were merged, but this will panic if resolvedIPsChan is already closed.
https://go.dev/play/p/I96AZ_2-kcf
It was better when select was used between this channel and reading quit, while resolvedIPsChan was left for GC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, I will change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😨😨😨

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@milan-zededa go back to use quit or go back and let the GC close resolvedIPsChan?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need both but maybe you have simpler solution in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually @OhmSpectator and I discussed and it seems, no change is necessary, because resolvedIPsChan will only be closed after

	defer func() {
		close(quit)
		<-wgChan
	}()

which will only finish after

	go func() {
		wg.Wait()
		close(wgChan)
	}()

which will only finish after all goroutines of the waitgroup finished and that means, that no goroutine can write into resolvedIPsChan

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true, I missed this.
This function is not for the faint-hearthed :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No risk, no fun :-)

use fancy uber leak checker to check for leaks
which have been fixed in the commit before

Signed-off-by: Christoph Ostarek <christoph@zededa.com>
(cherry picked from commit 145e98e)
@github-actions github-actions bot requested a review from milan-zededa November 6, 2024 15:19
@OhmSpectator OhmSpectator merged commit 6858178 into lf-edge:13.4-stable Nov 6, 2024
61 of 73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants