kubernetes-csi / external-resizer

Sidecar container that watches Kubernetes PersistentVolumeClaims objects and triggers controller side expansion operation against a CSI endpoint
Apache License 2.0
126 stars 132 forks source link

util/slowset: fix data race #433

Closed huww98 closed 3 months ago

huww98 commented 3 months ago

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change /kind bug /kind cleanup /kind design /kind documentation /kind failing-test /kind feature /kind flake

/kind bug /kind failing-test

What this PR does / why we need it:

Reported by go test -race. Also use time.Ticker to response faster to stopCh.

Which issue(s) this PR fixes:

Fixes #418 Fixes 99cf66fd7606604ac3dd101b6a8141d9ff9a1366

Special notes for your reviewer:

=== RUN   TestSlowSet
=== RUN   TestSlowSet/Should_not_change_time_of_a_key_if_added_multiple_times
=== RUN   TestSlowSet/Should_remove_key_after_retention_time
==================
WARNING: DATA RACE
Read at 0x00c000318060 by goroutine 43:
  runtime.mapiterinit()
      /usr/local/go/src/runtime/map.go:816 +0x0
  github.com/kubernetes-csi/external-resizer/pkg/util.(*SlowSet).Run()
      /workspace/output/pkg/util/slowset.go:91 +0x144
  github.com/kubernetes-csi/external-resizer/pkg/util.TestSlowSet.func6.gowrap1()
      /workspace/output/pkg/util/slowset_test.go:96 +0x44
Previous write at 0x00c000318060 by goroutine 42:
  runtime.mapassign_faststr()
      /usr/local/go/src/runtime/map_faststr.go:203 +0x0
  github.com/kubernetes-csi/external-resizer/pkg/util.(*SlowSet).Add()
      /workspace/output/pkg/util/slowset.go:52 +0x1c4
  github.com/kubernetes-csi/external-resizer/pkg/util.TestSlowSet.func2()
      /workspace/output/pkg/util/slowset_test.go:49 +0x32
  github.com/kubernetes-csi/external-resizer/pkg/util.TestSlowSet.func6()
      /workspace/output/pkg/util/slowset_test.go:98 +0x31a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44
Goroutine 43 (running) created at:
  github.com/kubernetes-csi/external-resizer/pkg/util.TestSlowSet.func6()
      /workspace/output/pkg/util/slowset_test.go:96 +0x28a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44
Goroutine 42 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1742 +0x825
  github.com/kubernetes-csi/external-resizer/pkg/util.TestSlowSet()
      /workspace/output/pkg/util/slowset_test.go:92 +0x2bb
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x44
==================

/cc @gnufied @jsafrane

Does this PR introduce a user-facing change?:

NONE
k8s-ci-robot commented 3 months ago

Hi @huww98. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
gnufied commented 3 months ago

Also, I am somewhat surprised that we aren't running our unit tests with -race flag. May be, we should. I don't see an obvious downside.

jsafrane commented 3 months ago

/ok-to-test

gnufied commented 3 months ago

/lgtm /approve

k8s-ci-robot commented 3 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnufied, huww98

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: - ~~[OWNERS](https://github.com/kubernetes-csi/external-resizer/blob/master/OWNERS)~~ [gnufied] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment