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

Keep Channel#close thread-safety #8249

Merged
merged 1 commit into from
Oct 9, 2019

Conversation

firejox
Copy link
Contributor

@firejox firejox commented Sep 29, 2019

If one thread is closing the channel and the other thread is sending data to channel, then both
threads may access the content simultaneously. It will be a bug under multi-thread environment.

@wooster0
Copy link
Contributor

Shouldn't the multi-threading flag preview_mt be used here?

@firejox
Copy link
Contributor Author

firejox commented Sep 29, 2019

@r00ster91 The spinlock has internally use the preview_mt flag. The lock and unlock operations will be no-op if the program is compiled without the flag. Hence, I think there is no need to use preview_mt here.

@bcardiff bcardiff added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:concurrency labels Sep 29, 2019
@bcardiff bcardiff requested a review from waj September 29, 2019 17:46
@firejox firejox force-pushed the channel-closed-thread-safety branch from 9758210 to a96d6bd Compare October 3, 2019 02:34
@bcardiff
Copy link
Member

bcardiff commented Oct 3, 2019

@firejox what is the use case that makes you deal with closed channels?

If possible keep the history of this PR with some experiments (or even specs) that is pushing you to iterate on the solution.

Thanks!

@firejox
Copy link
Contributor Author

firejox commented Oct 3, 2019

@bcardiff Sorry, I just trace the channel.cr and find there is no lock protection on Channel#close. I will rollback the change because the new change is less related to this race bug.

@firejox firejox force-pushed the channel-closed-thread-safety branch from a96d6bd to e0034ff Compare October 3, 2019 04:27
@bcardiff
Copy link
Member

bcardiff commented Oct 3, 2019

I thought you've found further issues and I was intrigued by a code to stress it.

@firejox
Copy link
Contributor Author

firejox commented Oct 3, 2019

The new change is for the situation that some channel is closed before the Channel.select cleaning up the context. And this is another issue.

@firejox firejox force-pushed the channel-closed-thread-safety branch from e0034ff to e8adef1 Compare October 8, 2019 17:21
@waj waj added this to the 0.32.0 milestone Oct 9, 2019
@waj waj merged commit 37ca414 into crystal-lang:master Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:concurrency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants