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

Locking appropriately before closing the channel to indicate migration #2231

Merged
merged 1 commit into from
Jan 23, 2017

Conversation

diptanu
Copy link
Contributor

@diptanu diptanu commented Jan 23, 2017

Fixes #2230

// migrateAllocCtrl indicates whether migration is complete
type migrateAllocCtrl struct {
ch chan struct{}
chLock sync.Mutex
Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Contributor

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

Copy link
Contributor Author

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()
Copy link
Member

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.

Copy link
Contributor Author

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.

@diptanu diptanu merged commit ef8c111 into master Jan 23, 2017
@diptanu diptanu deleted the b-close-ch branch January 23, 2017 18:50
@dadgar
Copy link
Contributor

dadgar commented Jan 23, 2017

@github-actions
Copy link

github-actions bot commented Apr 6, 2023

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants