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

dial queue: fix possible goroutine leak #262

Merged
merged 2 commits into from
Feb 19, 2019

Conversation

raulk
Copy link
Member

@raulk raulk commented Feb 13, 2019

On context cancellation, the ChanQueue stops its loop but keeps the EnqChan channel open. Under the right conditions, this could cause a worker goroutine to leak by blocking forever when sending to EnqChan, as nobody would be receiving any longer.

This race is fixed by attaching a separate context to the ChanQueue whose cancellation we control. Only after all workers have yielded (fenced by a WaitGroup), do we close the ChanQueue.


EDIT: force pushed a simpler solution as suggested by @Stebalien: #262 (review)

@raulk raulk requested a review from Kubuxu February 13, 2019 15:56
@ghost ghost assigned raulk Feb 13, 2019
@ghost ghost added the status/in-progress In progress label Feb 13, 2019
@raulk raulk requested review from Stebalien and anacrolix February 13, 2019 15:56
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

This works but wouldn't a simpler fix be to select on the context when writing to EnqChan in worker()?

@anacrolix
Copy link
Contributor

I think the dial queue code is too large and complex, I defer to @Stebalien if he's looked into it.

@raulk raulk force-pushed the fix/dialqueue-enqchan branch from deecef9 to c04565f Compare February 19, 2019 18:11
@raulk raulk force-pushed the fix/dialqueue-enqchan branch from c04565f to 4f0cf48 Compare February 19, 2019 18:12
@raulk raulk merged commit 5f67727 into libp2p:master Feb 19, 2019
@raulk raulk deleted the fix/dialqueue-enqchan branch February 19, 2019 22:42
@ghost ghost removed the status/in-progress In progress label Feb 19, 2019
anacrolix added a commit that referenced this pull request Mar 6, 2019
This reverts commit 5f67727, reversing
changes made to 52b75dd.
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