Skip to content

Commit

Permalink
Fix panic in Task FrameWork, fixes #5034 (#5081)
Browse files Browse the repository at this point in the history
(cherry-picked from commit 8482527)
  • Loading branch information
mangalaman93 authored and parasssh committed Apr 8, 2020
1 parent 07de78a commit d6f6519
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions worker/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const (
// startTask is used to check whether an op is already going on.
// If rollup is going on, we cancel and wait for rollup to complete
// before we return. If the same task is already going, we return error.
// You should only call Done() on the returned closer. Calling other
// functions (such as SignalAndWait) for closer could result in panics.
// For more details, see GitHub issue #5034.
func (n *node) startTask(id op) (*y.Closer, error) {
n.opsLock.Lock()
defer n.opsLock.Unlock()
Expand Down Expand Up @@ -125,6 +128,8 @@ func (n *node) startTask(id op) (*y.Closer, error) {
case opSnapshot, opIndexing:
for otherId, otherCloser := range n.ops {
if otherId == opRollup {
// We set to nil so that stopAllTasks doesn't call SignalAndWait again.
n.ops[opRollup] = nil
otherCloser.SignalAndWait()
} else {
return nil, errors.Errorf("operation %s is already running", otherId)
Expand Down Expand Up @@ -158,14 +163,12 @@ func (n *node) stopAllTasks() {
defer n.closer.Done() // CLOSER:1
<-n.closer.HasBeenClosed()

var closers []*y.Closer
n.opsLock.Lock()
defer n.opsLock.Unlock()
for _, closer := range n.ops {
closers = append(closers, closer)
}
n.opsLock.Unlock()

for _, closer := range closers {
if closer == nil {
continue
}
closer.SignalAndWait()
}
glog.Infof("Stopped all ongoing registered tasks.")
Expand Down

0 comments on commit d6f6519

Please sign in to comment.