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

Add -race Flag to GitHub Action and Fix Data Race in CreateTailscaleNodesInUser #2038

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nadongjun
Copy link
Contributor

@nadongjun nadongjun commented Jul 30, 2024

  • have read the CONTRIBUTING.md file
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md
  • This PR adds the -race flag to both unit and integration tests and addresses data race issues in the CreateTailscaleNodesInUser method.

The changes include:

  • Added -race flag: Included the -race flag in both test and test_integration targets in the Makefile to enable race condition detection for unit and integration tests. Github action is also configured to detect data races.
  • Fixed data race in CreateTailscaleNodesInUser: Updated the CreateTailscaleNodesInUser method to resolve data race issues related to concurrent access.

Log

WARNING: DATA RACE
Read at 0x00c000356030 by goroutine 106:
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser.func1()
      /Users/dongjunna/br/headscale/integration/scenario.go:336 +0x84
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /go/pkg/mod/golang.org/x/sync@v0.7.0/errgroup/errgroup.go:78 +0x7c

Previous write at 0x00c000356030 by goroutine 8:
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser()
      /Users/dongjunna/br/headscale/integration/scenario.go:330 +0x574
  github.com/juanfont/headscale/integration.(*Scenario).CreateHeadscaleEnv()
      /Users/dongjunna/br/headscale/integration/scenario.go:481 +0x218
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable.func1()
      /Users/dongjunna/br/headscale/integration/acl_test.go:274 +0x120
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Goroutine 106 (running) created at:
  golang.org/x/sync/errgroup.(*Group).Go()
      /go/pkg/mod/golang.org/x/sync@v0.7.0/errgroup/errgroup.go:75 +0x10c
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser()
      /Users/dongjunna/br/headscale/integration/scenario.go:335 +0x19c
  github.com/juanfont/headscale/integration.(*Scenario).CreateHeadscaleEnv()
      /Users/dongjunna/br/headscale/integration/scenario.go:481 +0x218
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable.func1()
      /Users/dongjunna/br/headscale/integration/acl_test.go:274 +0x120
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Goroutine 8 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1742 +0x5e4
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable()
      /Users/dongjunna/br/headscale/integration/acl_test.go:268 +0x1f6c
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40
==================
==================
WARNING: DATA RACE
Read at 0x00c0001961d0 by goroutine 106:
  github.com/juanfont/headscale/integration/tsic.New()
      /Users/dongjunna/br/headscale/integration/tsic/tsic.go:195 +0x38c
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser.func1()
      /Users/dongjunna/br/headscale/integration/scenario.go:336 +0xa8
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /go/pkg/mod/golang.org/x/sync@v0.7.0/errgroup/errgroup.go:78 +0x7c

Previous write at 0x00c0001961d0 by goroutine 8:
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser()
      /Users/dongjunna/br/headscale/integration/scenario.go:330 +0x4ec
  github.com/juanfont/headscale/integration.(*Scenario).CreateHeadscaleEnv()
      /Users/dongjunna/br/headscale/integration/scenario.go:481 +0x218
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable.func1()
      /Users/dongjunna/br/headscale/integration/acl_test.go:274 +0x120
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Goroutine 106 (running) created at:
  golang.org/x/sync/errgroup.(*Group).Go()
      /go/pkg/mod/golang.org/x/sync@v0.7.0/errgroup/errgroup.go:75 +0x10c
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser()
      /Users/dongjunna/br/headscale/integration/scenario.go:335 +0x19c
  github.com/juanfont/headscale/integration.(*Scenario).CreateHeadscaleEnv()
      /Users/dongjunna/br/headscale/integration/scenario.go:481 +0x218
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable.func1()
      /Users/dongjunna/br/headscale/integration/acl_test.go:274 +0x120
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Goroutine 8 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1742 +0x5e4
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable()
      /Users/dongjunna/br/headscale/integration/acl_test.go:268 +0x1f6c
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40
==================
==================
WARNING: DATA RACE
Read at 0x00c0001961d8 by goroutine 106:
  github.com/juanfont/headscale/integration/tsic.New()
      /Users/dongjunna/br/headscale/integration/tsic/tsic.go:195 +0x38c
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser.func1()
      /Users/dongjunna/br/headscale/integration/scenario.go:336 +0xa8
  golang.org/x/sync/errgroup.(*Group).Go.func1()
      /go/pkg/mod/golang.org/x/sync@v0.7.0/errgroup/errgroup.go:78 +0x7c

Previous write at 0x00c0001961d8 by goroutine 8:
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser()
      /Users/dongjunna/br/headscale/integration/scenario.go:330 +0x530
  github.com/juanfont/headscale/integration.(*Scenario).CreateHeadscaleEnv()
      /Users/dongjunna/br/headscale/integration/scenario.go:481 +0x218
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable.func1()
      /Users/dongjunna/br/headscale/integration/acl_test.go:274 +0x120
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Goroutine 106 (running) created at:
  golang.org/x/sync/errgroup.(*Group).Go()
      /go/pkg/mod/golang.org/x/sync@v0.7.0/errgroup/errgroup.go:75 +0x10c
  github.com/juanfont/headscale/integration.(*Scenario).CreateTailscaleNodesInUser()
      /Users/dongjunna/br/headscale/integration/scenario.go:335 +0x19c
  github.com/juanfont/headscale/integration.(*Scenario).CreateHeadscaleEnv()
      /Users/dongjunna/br/headscale/integration/scenario.go:481 +0x218
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable.func1()
      /Users/dongjunna/br/headscale/integration/acl_test.go:274 +0x120
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Goroutine 8 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:1742 +0x5e4
  github.com/juanfont/headscale/integration.TestACLHostsInNetMapTable()
      /Users/dongjunna/br/headscale/integration/acl_test.go:268 +0x1f6c
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1689 +0x180
  testing.(*T).Run.gowrap1()
      /usr/local/go/src/testing/testing.go:1742 +0x40

Summary by CodeRabbit

  • New Features

    • Enhanced testing process by adding race detection for both unit and integration tests.
  • Bug Fixes

    • Improved concurrency control in command execution and Tailscale node creation to prevent race conditions, enhancing reliability.
  • Style

    • Cleaned up whitespace for better code formatting.

@kradalby
Copy link
Collaborator

Good job, looks like there are some more races!

@kradalby
Copy link
Collaborator

@nadongjun do you have time to have a look at the failing tests?

@nadongjun
Copy link
Contributor Author

@kradalby Sure, I should be able to complete that by the end of this week.

Signed-off-by: Dongjun Na <kmu5544616@gmail.com>
Copy link
Contributor

coderabbitai bot commented Aug 20, 2024

Walkthrough

This update enhances the testing framework and concurrency control across various components. The addition of the -race flag to testing commands improves the detection of race conditions in both unit and integration tests. Concurrent output handling mechanisms are refined in the ExecuteCommand function, while mutex locks are introduced in the CreateTailscaleNodesInUser method to ensure thread safety. Overall, these changes bolster the reliability and robustness of the code.

Changes

File Path Change Summary
.github/workflows/test-integration.yaml, Makefile Added -race flag to testing commands, enhancing race condition detection during unit and integration tests.
integration/dockertestutil/execute.go Introduced sync.Mutex for synchronized access to output buffers, improving thread safety in command execution.
integration/scenario.go Added mutex locks around shared resource access in CreateTailscaleNodesInUser, enhancing concurrency control.

Poem

In the garden where code bunnies play,
We fixed the tests, hip-hip-hooray! 🐇✨
With -race to catch a sneaky bug,
Our tests now hug and snugly snug.
Mutexes dance, a safe embrace,
Together we leap, in the coding race! 🥕💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 06f0705 and 126177c.

Files selected for processing (4)
  • .github/workflows/test-integration.yaml (1 hunks)
  • Makefile (2 hunks)
  • integration/dockertestutil/execute.go (5 hunks)
  • integration/scenario.go (1 hunks)
Additional context used
golangci-lint
integration/dockertestutil/execute.go

41-41: variable name 'mu' is too short for the scope of its usage

(varnamelen)

Additional comments not posted (6)
Makefile (2)

25-25: Incorporate race detection in unit tests.

The addition of the -race flag to the gotestsum command in the test target enhances the detection of race conditions during unit testing.


36-36: Incorporate race detection in integration tests.

The addition of the -race flag to the gotestsum command in the test_integration target enhances the detection of race conditions during integration testing.

integration/dockertestutil/execute.go (1)

63-78: Enhance thread safety with local buffers and mutex.

The use of local buffers for capturing command output and the addition of a mutex to synchronize writes to shared buffers effectively prevent race conditions.

.github/workflows/test-integration.yaml (1)

104-104: Enhance race condition detection in GitHub Actions.

The inclusion of the -race flag in the test command within the GitHub Actions workflow improves the detection of race conditions during integration testing.

integration/scenario.go (2)

330-335: Ensure thread safety with mutex locks.

The addition of mutex locks around shared resource access in CreateTailscaleNodesInUser helps prevent race conditions, enhancing the method's reliability.


338-345: Maintain thread safety during Tailscale client creation.

Mutex locks are correctly used to ensure thread safety during the creation of Tailscale clients, preventing concurrent access issues.

integration/dockertestutil/execute.go Outdated Show resolved Hide resolved
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.

2 participants