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

Prevent Check to send result to closed channel #85

Merged
merged 2 commits into from
Oct 21, 2022
Merged

Conversation

lucasmdrs
Copy link
Contributor

@lucasmdrs lucasmdrs commented Oct 20, 2022

This PR prevents a race condition between timeout and the Check execution result by delegating the closing command to the goroutine where the Check work done.

Since the work happened before checking the channel state the performance should not be impacted.

Closes #84

@lucasmdrs lucasmdrs marked this pull request as ready for review October 20, 2022 14:34
@lucasmdrs lucasmdrs merged commit c509188 into master Oct 21, 2022
@lucasmdrs lucasmdrs deleted the patch-issue-84 branch October 21, 2022 12:21
resCh <- res
}
resCh <- c.Check(ctx)
defer close(resCh)
Copy link

Choose a reason for hiding this comment

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

@lucasmdrs , the defer should be before the Check, no? if the Check does not end, this will never get closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @grzn
Changing the order of the defer would not change anything, endless checks will always result in leaky goroutines.

The changes done here will make open channels not be closed until those goroutines are finished.
It's still not the best solution, but ensures that there's no race condition between timeouts and checks

I'll work to improve this entire logic a bit, but that will be out of the scope for the issue

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.

panic: send on closed channel
3 participants