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

prevent data race in testing artifact fetcher #3685

Merged
merged 2 commits into from
Nov 2, 2023

Conversation

leehinman
Copy link
Contributor

What does this PR do?

Switch from uint64 to an atomic.Uint64 to prevent data race in testing artifact fetcher

Why is it important?

In CI we can see the data race:

==================
WARNING: DATA RACE
Read at 0x00c0002dbc18 by goroutine 11:
  github.com/elastic/elastic-agent/pkg/testing.(*writeProgress).printProgress()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:285 +0x158
  github.com/elastic/elastic-agent/pkg/testing.newWriteProgress.func1()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:267 +0x4c

Previous write at 0x00c0002dbc18 by goroutine 9:
  github.com/elastic/elastic-agent/pkg/testing.(*writeProgress).Write()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:273 +0x50
  io.(*teeReader).Read()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/io/io.go:615 +0xac
  io.copyBuffer()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/io/io.go:427 +0x1ec
  io.Copy()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/io/io.go:386 +0x74
  os.genericReadFrom()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/os/file.go:161 +0x2c
  os.(*File).ReadFrom()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/os/file.go:155 +0x2b0
  io.copyBuffer()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/io/io.go:413 +0x154
  io.Copy()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/io/io.go:386 +0x398
  github.com/elastic/elastic-agent/pkg/testing.DownloadPackage()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:243 +0x320
  github.com/elastic/elastic-agent/pkg/testing.(*artifactResult).Fetch()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:110 +0x284
  github.com/elastic/elastic-agent/pkg/testing.TestArtifactFetcher_SnapshotOnly()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact_test.go:95 +0xa10
  testing.tRunner()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1576 +0x180
  testing.(*T).Run.func1()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1629 +0x40

Goroutine 11 (running) created at:
  github.com/elastic/elastic-agent/pkg/testing.newWriteProgress()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:267 +0x168
  github.com/elastic/elastic-agent/pkg/testing.DownloadPackage()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:237 +0x268
  github.com/elastic/elastic-agent/pkg/testing.(*artifactResult).Fetch()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact.go:110 +0x284
  github.com/elastic/elastic-agent/pkg/testing.TestArtifactFetcher_SnapshotOnly()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/src/github.com/elastic/elastic-agent/pkg/testing/fetcher_artifact_test.go:95 +0xa10
  testing.tRunner()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1576 +0x180
  testing.(*T).Run.func1()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1629 +0x40

Goroutine 9 (running) created at:
  testing.(*T).Run()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1629 +0x5b4
  testing.runTests.func1()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:2036 +0x80
  testing.tRunner()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1576 +0x180
  testing.runTests()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:2034 +0x6a8
  testing.(*M).Run()
      /var/lib/jenkins/workspace/tic-agent_elastic-agent-mbp_8.11/.gvm/versions/go1.20.10.linux.arm64/src/testing/testing.go:1906 +0x8e0
  main.main()
      _testmain.go:59 +0x2b8
==================

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Author's Checklist

How to test this PR locally

go test -v -race ./pkg/testing -run TestArtifactFetcher_SnapshotOnly -count 10000

Related issues

Use cases

Screenshots

Logs

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

@leehinman leehinman requested a review from a team as a code owner November 1, 2023 18:31
@leehinman leehinman added the Team:Elastic-Agent Label for the Agent team label Nov 1, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

@leehinman leehinman added the backport-v8.11.0 Automated backport with mergify label Nov 1, 2023
Copy link
Contributor

mergify bot commented Nov 1, 2023

This pull request does not have a backport label. Could you fix it @leehinman? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

elasticmachine commented Nov 1, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-11-02T13:45:28.272+0000

  • Duration: 16 min 3 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@cmacknz
Copy link
Member

cmacknz commented Nov 1, 2023

Merge in main to get past the buildkite failure

@leehinman leehinman enabled auto-merge (squash) November 1, 2023 20:27
@cmacknz
Copy link
Member

cmacknz commented Nov 2, 2023

@Mergifyio update

Copy link
Contributor

mergify bot commented Nov 2, 2023

update

✅ Branch has been successfully updated

@cmacknz cmacknz linked an issue Nov 2, 2023 that may be closed by this pull request
@cmacknz
Copy link
Member

cmacknz commented Nov 2, 2023

buildkite test it

Copy link

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@leehinman leehinman merged commit de1bda7 into elastic:main Nov 2, 2023
7 checks passed
mergify bot pushed a commit that referenced this pull request Nov 2, 2023
@leehinman leehinman deleted the fetcher_artifact_race branch November 2, 2023 19:20
leehinman added a commit that referenced this pull request Nov 3, 2023
(cherry picked from commit de1bda7)

Co-authored-by: Lee E Hinman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.11.0 Automated backport with mergify skip-changelog Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flaky test: TestArtifactFetcher_SnapshotOnly
4 participants