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

[BUG] data race in states_informer_test.go #77

Closed
jasonliu747 opened this issue Apr 16, 2022 · 2 comments · Fixed by #153
Closed

[BUG] data race in states_informer_test.go #77

jasonliu747 opened this issue Apr 16, 2022 · 2 comments · Fixed by #153
Assignees
Labels
kind/bug Create a report to help us improve
Milestone

Comments

@jasonliu747
Copy link
Member

What happened:
I ran test with race detection enabled using go test ./... -race, and it would fail with followig errors:

W0416 10:52:14.139957   51219 metrics.go:60] register nil node for metrics
E0416 10:52:14.140726   51219 pleg.go:82] failed to create pod watcherwatch not supported on darwin
E0416 10:52:14.140778   51219 pleg.go:86] failed to create container watcherwatch not supported on darwin
I0416 10:52:14.141045   51219 states_informer.go:111] starting statesInformer
I0416 10:52:14.141081   51219 states_informer.go:113] starting informer for Node
I0416 10:52:14.244944   51219 states_informer.go:135] start meta service successfully
I0416 10:52:14.245620   51219 states_informer.go:212] get pods from kubelet success, len 1
==================
WARNING: DATA RACE
Read at 0x00c0001d2628 by goroutine 44:
  runtime.racereadrange()
      <autogenerated>:1 +0x1b
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1259 +0x22f
  testing.(*T).Run·dwrap·21()
      /usr/local/go/src/testing/testing.go:1306 +0x47

Previous write at 0x00c0001d2628 by goroutine 59:
  github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer.(*statesInformer).syncKubelet()
      /Users/jason/Projects/koordinator/pkg/koordlet/statesinformer/states_informer.go:211 +0x358
  github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer.(*statesInformer).syncKubeletLoop()
      /Users/jason/Projects/koordinator/pkg/koordlet/statesinformer/states_informer.go:226 +0x2f1
  github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer.(*statesInformer).Run·dwrap·4()
      /Users/jason/Projects/koordinator/pkg/koordlet/statesinformer/states_informer.go:130 +0x58

Goroutine 44 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1306 +0x726
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1598 +0x99
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1259 +0x22f
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1596 +0x7ca
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1504 +0x9d1
  main.main()
      _testmain.go:103 +0x324

Goroutine 59 (running) created at:
  github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer.(*statesInformer).Run()
      /Users/jason/Projects/koordinator/pkg/koordlet/statesinformer/states_informer.go:130 +0x714
  github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer.Test_metaService_syncPods·dwrap·13()
      /Users/jason/Projects/koordinator/pkg/koordlet/statesinformer/states_informer_test.go:181 +0x59
==================

Environment:

  • Go version: go version go1.17.9 darwin/amd64
@jasonliu747
Copy link
Member Author

jasonliu747 commented Apr 16, 2022

/assign @zwzhang0107
I'll remove these codes in the upcoming PR temporarily to solve CI errors. But please fix it ASAP.

type testKubeletStub struct {
pods corev1.PodList
}
func (t *testKubeletStub) GetAllPods() (corev1.PodList, error) {
return t.pods, nil
}
func Test_metaService_syncPods(t *testing.T) {
client := clientsetfake.NewSimpleClientset()
pleg, _ := pleg.NewPLEG(sysutil.Conf.CgroupRootDir)
stopCh := make(chan struct{})
defer close(stopCh)
c := NewDefaultConfig()
c.KubeletSyncIntervalSeconds = 60
m := NewStatesInformer(c, client, pleg, "localhost")
m.(*statesInformer).kubelet = &testKubeletStub{pods: corev1.PodList{
Items: []corev1.Pod{
{},
},
}}
go m.Run(stopCh)
m.(*statesInformer).podCreated <- "pod1"
time.Sleep(200 * time.Millisecond)
if time.Since(m.(*statesInformer).podUpdatedTime) > time.Second {
t.Errorf("failed to triggle update by pod created event")
}
if len(m.(*statesInformer).podMap) != 1 {
t.Errorf("failed to update pods")
}
}

@jasonliu747
Copy link
Member Author

/kind bug

@koordinator-bot koordinator-bot bot added the kind/bug Create a report to help us improve label Apr 28, 2022
@jasonliu747 jasonliu747 added this to the v0.4 milestone May 21, 2022
@jasonliu747 jasonliu747 linked a pull request May 21, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Create a report to help us improve
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants