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

copr: fix data race in the mppIterator #39772

Merged
merged 8 commits into from
Dec 9, 2022
7 changes: 5 additions & 2 deletions store/copr/mpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ type mppIterator struct {

cancelFunc context.CancelFunc

wg sync.WaitGroup
wg sync.WaitGroup
wgDoneChan chan struct{}

closed uint32

Expand Down Expand Up @@ -188,6 +189,7 @@ func (m *mppIterator) run(ctx context.Context) {
}(task)
}
m.wg.Wait()
close(m.wgDoneChan)
close(m.respChan)
}

Expand Down Expand Up @@ -446,7 +448,7 @@ func (m *mppIterator) Close() error {
close(m.finishCh)
}
m.cancelFunc()
m.wg.Wait()
Copy link
Member Author

Choose a reason for hiding this comment

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

We must not use two wg.wait() parallelly.

<-m.wgDoneChan
return nil
}

Expand Down Expand Up @@ -533,6 +535,7 @@ func (c *MPPClient) DispatchMPPTasks(ctx context.Context, variables interface{},
store: c.store,
tasks: dispatchReqs,
finishCh: make(chan struct{}),
wgDoneChan: make(chan struct{}),
cancelFunc: cancelFunc,
respChan: make(chan *mppResponse),
startTs: startTs,
Expand Down