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

ca: Readd WaitGroup to Server #1854

Merged
merged 1 commit into from Jan 10, 2017
Merged

Conversation

aaronlehmann
Copy link
Collaborator

@aaronlehmann aaronlehmann commented Jan 10, 2017

The WaitGroup was removed as a simplification in #1841, but this causes (*Server).Stop to potentially return before Run is finished. This is unwanted behavior that causes data races in tests. Readd the WaitGroup, but only use it to wait for Run to finish, not RPC handlers.

cc @dperny @cyli

The WaitGroup was removed as a simplification, but this causes
(*Server).Stop to potentially return before Run is finished. This is
unwanted behavior that causes data races in tests. Readd the WaitGroup,
but only use it to wait for Run to finish, not RPC handlers.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
@@ -464,7 +467,12 @@ func (s *Server) Run(ctx context.Context) error {
// Stop stops the CA and closes all grpc streams.
func (s *Server) Stop() error {
s.mu.Lock()

// Wait for Run to complete before returning
defer s.wg.Wait()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be called after the check for !s.isRunning()?

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternately, maybe only call wait if s.isRunning(), since otherwise won't s.isRunning() always be false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I want it to wait in that case as well, because Run may not have picked up the context cancellation yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

It may not matter, since I don't think we're checking the error returned by Stop, but would this mean that Stop() always returns an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, s.cancel() seems to be called after the check for !s.isRunning() - would this just block unless something else cancelled the Run context?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nm, for some reason my eyes kept slipping passed the word defer

@cyli
Copy link
Contributor

cyli commented Jan 10, 2017

LGTM

@aaronlehmann
Copy link
Collaborator Author

Merging this to fix CI on master. Feel free to do more review after the fact.

@aaronlehmann aaronlehmann merged commit c80ff0c into moby:master Jan 10, 2017
@aaronlehmann aaronlehmann deleted the ca-waitgroup branch January 10, 2017 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants