Skip to content

Commit

Permalink
oversight: fix panic on restart of canceled trees
Browse files Browse the repository at this point in the history
  • Loading branch information
ucirello committed Jan 13, 2022
1 parent 6f2109d commit 2e4c6e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ func (t *Tree) Start(rootCtx context.Context) error {
}

func (t *Tree) drain(ctx context.Context) error {
select {
case <-t.stopped:
return ErrTreeNotRunning
default:
}
close(t.stopped)
defer t.logger.Printf("clean up complete")
t.logger.Printf("context canceled (before start): %v", ctx.Err())
Expand Down
9 changes: 9 additions & 0 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,3 +1061,12 @@ func TestTree_shutdownOrder(t *testing.T) {
})
})
}

func TestPanicDoubleStart(t *testing.T) {
var tree oversight.Tree
oversight.NeverHalt()(&tree)
ctx, cancel := context.WithCancel(context.Background())
tree.Add(oversight.ChildProcessSpecification{Name: "child", Start: func(context.Context) error { cancel(); return nil }})
tree.Start(ctx)
tree.Start(ctx)
}

0 comments on commit 2e4c6e6

Please sign in to comment.