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

more conservative channel behavior for waiters #756

Merged
merged 2 commits into from
Oct 5, 2020
Merged

Conversation

willscott
Copy link
Member

It was possible for a sequence to occur of:

  • Watch loop pulls pending list. unlocks lock.
  • Waiter triggered by 'Done' context gets lock. checks list and sees it isn't there. closes it's watch channel.
  • Watch loop attempts signalling waiter on now-closed channel. panics.

This keeps the lock held by the watch loop during signalling.

@@ -186,7 +186,8 @@ func (h *handler) getRand(ctx context.Context, info *chain.Info, round uint64) (
h.pendingLk.RUnlock()
// If so, prepare, and if we're still sync'd, add ourselves to the list of waiters.
if block {
ch := make(chan []byte)
ch := make(chan []byte, 1)
defer close(ch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to use the more safe Go pattern where the sender closes the channel, instead of the receiver ? so the receiver can simply for _ := range myChan { .. } safely.

Copy link
Member Author

Choose a reason for hiding this comment

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

would you do it with a different channel for the receiver to notify the sender that its context has closed then?

@willscott willscott merged commit 112037f into master Oct 5, 2020
@willscott willscott deleted the fix/waitpanic branch October 5, 2020 14:38
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.

None yet

2 participants