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

Fix some race conditions #123

Merged
merged 5 commits into from
Jan 24, 2020
Merged

Fix some race conditions #123

merged 5 commits into from
Jan 24, 2020

Conversation

wallrj
Copy link
Contributor

@wallrj wallrj commented Dec 19, 2019

  • Wait for controller manager to exit before exiting the test (prevents calls to t.Log after the test has finished)
  • Add Lock around the setting and reading from the fake Etcd client (prevents the controller using a MembershipAPI which has been replaced in the test)
  • Return a copy of the members list (prevents controller using a members list which might be mutated during the test)

The controller-runtime manager.Start doesn't wait for all its go-routines to finish,
which leads to another race when the controller runtime attempts to log (via t.Log) after a test has finished.
See:

Part of: #117

@wallrj wallrj changed the title WIP: Enable race checker in CI WIP: Enable race checker in CI and fix some race conditions Dec 19, 2019
@wallrj
Copy link
Contributor Author

wallrj commented Dec 19, 2019

You can see the leaked goroutine in the test results;

Goroutine 270 (running) created at:
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start()
      /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:157 +0x4ee
  sigs.k8s.io/controller-runtime/pkg/manager.(*controllerManager).startLeaderElectionRunnables.func1()
      /go/pkg/mod/sigs.k8s.io/[email protected]/pkg/manager/internal.go:326 +0x74

--- https://app.circleci.com/jobs/github/improbable-eng/etcd-cluster-operator/668/parallel-runs/0/steps/0-102

@wallrj wallrj changed the title WIP: Enable race checker in CI and fix some race conditions Fix some race conditions Jan 3, 2020
@wallrj
Copy link
Contributor Author

wallrj commented Jan 3, 2020

I've removed the -race parameter now.
We will have to enable the race checks once the bug has been fixed in controller-runtime.
Meanwhile this fixes three of the race conditions.

@@ -41,7 +41,7 @@ type StaticResponseMembersAPI struct {
}

func (s *StaticResponseMembersAPI) List(ctx context.Context) ([]etcdclient.Member, error) {
return s.parent.Members, nil
return s.parent.Members[:], nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This new slice doesn't copy the underlying members does it? So if you modified the Members themselves it would still mutate the old slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I didn't bother, because I was concentrating on fixing the race conditions, but I've now added a deep copy function to avoid any accidental mutation of the Member list.

@wallrj wallrj merged commit 89bcf01 into improbable-eng:master Jan 24, 2020
@wallrj wallrj deleted the race-check branch January 24, 2020 13:11
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.

3 participants