-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix server shutdown not waiting for worker run completion (#19560) * Move group into a separate helper module for reuse * Add shutdownCh to worker The shutdown channel is used to signal that worker has stopped. * Make server shutdown block on workers' shutdownCh * Fix waiting for eval broker state change blocking indefinitely There was a race condition in the GenericNotifier between the Run and WaitForChange functions, where WaitForChange blocks trying to write to a full unsubscribeCh, but the Run function never reads from the unsubscribeCh as it has already stopped. This commit fixes it by unblocking if the notifier has been stopped. * Bound the amount of time server shutdown waits on worker completion * Fix lostcancel linter error * Fix worker test using unexpected worker constructor * Add changelog --------- Co-authored-by: Marvin Chin <[email protected]>
- Loading branch information
Showing
11 changed files
with
129 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
server: Fix server not waiting for workers to submit nacks for dequeued evaluations before shutting down | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package group | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
) | ||
|
||
// group wraps a func() in a goroutine and provides a way to block until it | ||
// exits. Inspired by https://godoc.org/golang.org/x/sync/errgroup | ||
type Group struct { | ||
wg sync.WaitGroup | ||
} | ||
|
||
// Go starts f in a goroutine and must be called before Wait. | ||
func (g *Group) Go(f func()) { | ||
g.wg.Add(1) | ||
go func() { | ||
defer g.wg.Done() | ||
f() | ||
}() | ||
} | ||
|
||
func (g *Group) AddCh(ch <-chan struct{}) { | ||
g.Go(func() { | ||
<-ch | ||
}) | ||
} | ||
|
||
// Wait for all goroutines to exit. Must be called after all calls to Go | ||
// complete. | ||
func (g *Group) Wait() { | ||
g.wg.Wait() | ||
} | ||
|
||
// Wait for all goroutines to exit, or for the context to finish. | ||
// Must be called after all calls to Go complete. | ||
func (g *Group) WaitWithContext(ctx context.Context) { | ||
doneCh := make(chan struct{}) | ||
go func() { | ||
defer close(doneCh) | ||
g.Wait() | ||
}() | ||
select { | ||
case <-doneCh: | ||
case <-ctx.Done(): | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.