-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix data races, simplify #2
Conversation
Hmm, looking at your usage in Packer, it looks like checking the cancelled state in the middle of a step run is a feature. In that case, we need to either wrap a |
What do you think about passing a channel in the state bag that gets closed if/when the run is cancelled? func (s ExStep) Run(state map[string]interface{}) StepAction {
for {
select {
case <-state[CancelChan].(<-chan struct{}):
return
default:
// work...
}
}
} We could also change the type of func (s ExStep) Run(state StateBag) StepAction {
for {
select {
case <-state.CancelNotify():
return
default:
// work...
}
}
} |
Whoops sorry I forgot to "watch" this repo. Haha. So I was initially going to use channels to do this. The issue, that I think is still present in this pull, is what if multiple people call |
Yep, receiving from a closed channel returns the zero value instantly, so |
Looks great, finally merging. Thanks. :) |
@titanous re: cancel access and stuff: Yeah, I think breaking API and introducing a state bag is the way to go. I didn't realize when I first wrote this the dangers of data races. |
@mitchellh Cool. I don't have time to implement that, but let me know if you have any questions. |
I've simplified the basic runner to check for cancellation before each step and use the close of a goroutine to synchronize waiting on Cancel().
Before this patch
go test -race
indicates data races:After, there are none: