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 deadlock in ready test #116251
Fix deadlock in ready test #116251
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wojtek-t The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
yeah, it can deadlock, great catch |
LGTM label has been added. Git tree hash: ca84027d46482b36b29888ae52b43a99c9224382
|
/hold this still can race |
if there is a deadlock and the context is cancaled it will return an error, the error will make the test fail and be flaky We need to ensure that the ready is set to true, check this diff , I think that this will f EDIT - the code was completely wrong EDIT2 -- this works diff --git a/staging/src/k8s.io/apiserver/pkg/storage/cacher/ready_test.go b/staging/src/k8s.io/apiserver/pkg/storage/cacher/ready_test.go
index e8720e2ad32..67dcb1a6a1c 100644
--- a/staging/src/k8s.io/apiserver/pkg/storage/cacher/ready_test.go
+++ b/staging/src/k8s.io/apiserver/pkg/storage/cacher/ready_test.go
@@ -18,6 +18,7 @@ package cacher
import (
"context"
+ "sync"
"testing"
"time"
)
@@ -82,21 +83,25 @@ func Test_newReadyRacy(t *testing.T) {
ready := newReady()
ready.set(false)
- ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
- defer cancel()
-
+ var wg sync.WaitGroup
for i := 0; i < concurrency; i++ {
+ wg.Add(2)
go func() {
- errCh <- ready.wait(ctx)
+ errCh <- ready.wait(context.Background())
}()
go func() {
+ defer wg.Done()
ready.set(false)
}()
go func() {
+ defer wg.Done()
ready.set(true)
}()
}
+ // last one has to set ready to true
+ wg.Wait()
ready.set(true)
|
ok - good catch, forgot about it. Yeah - what you have makes sense - changing. |
/lgtm |
LGTM label has been added. Git tree hash: 585146b78161861f4ac3d832ef83fe96e9c4d754
|
/triage accepted |
…1-upstream-release-1.24 Automated cherry pick of #116251: Fix deadlock in ready test
…1-upstream-release-1.25 Automated cherry pick of #116251: Fix deadlock in ready test
…1-upstream-release-1.26 Automated cherry pick of #116251: Fix deadlock in ready test
Fix #116225
/kind flake
/sig api-machinery
/priority important-soon
/assign @aojea