-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Locking appropriately before closing the channel to indicate migration #2231
Conversation
// migrateAllocCtrl indicates whether migration is complete | ||
type migrateAllocCtrl struct { | ||
ch chan struct{} | ||
chLock sync.Mutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add closed bool
m.chLock.Lock() | ||
defer m.chLock.Unlock() | ||
|
||
// If channel is not closed then close it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m.chLock.Lock()
defer m.chLock.Unlock()
if m.closed {
return
}
m.closed = true
close(m.ch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation will actually block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it doesn't block and return false immediately when the ch is closed.
} | ||
|
||
func (m *migrateAllocCtrl) closeCh() { | ||
m.chLock.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this lock as runAllocs
method is only ever called from a single goroutine so all chan mutations are serialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be called concurrently though.
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Fixes #2230