Skip to content

acquire lock in addEdges() #5479

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

Merged
merged 3 commits into from
May 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions worker/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,14 @@ func (e *executor) shutdown() {
}
}

func (e *executor) getChannel(pred string) (ch chan *subMutation) {
e.RLock()
// getChannelUnderLock obtains the channel for the given pred. It must be called under e.Lock().
func (e *executor) getChannelUnderLock(pred string) (ch chan *subMutation) {
ch, ok := e.predChan[pred]
e.RUnlock()
if ok {
return ch
}

// Create a new channel for `pred`.
e.Lock()
defer e.Unlock()
ch, ok = e.predChan[pred]
if ok {
return ch
Expand All @@ -123,7 +120,17 @@ func (e *executor) addEdges(ctx context.Context, startTs uint64, edges []*pb.Dir
payload.edges = append(payload.edges, edge)
}

for attr, payload := range payloadMap {
e.getChannel(attr) <- payload
// Lock() in case the channel gets closed from underneath us.
e.Lock()
defer e.Unlock()
select {
case <-e.closer.HasBeenClosed():
return
default:
// Closer is not closed. And we have the Lock, so sending on channel should be safe.
for attr, payload := range payloadMap {
e.getChannelUnderLock(attr) <- payload
}
}

}