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

fix: data race on Systray.SetCurrentConfigFile #1012

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

Conversation

dido18
Copy link
Contributor

@dido18 dido18 commented Jan 21, 2025

Please check if the PR fulfills these requirements

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • Tests for the changes have been added (for bug fixes / features)
  • What kind of change does this PR introduce?
    Fix a data race on the config set to the Systray struct.
  • What is the current behavior?
    When the agent starts, there is a data race on the SetCurrentConfigFile method called by two different go routines.
2025/01/10 14:35:07 stderr: WARNING: DATA RACE
2025/01/10 14:35:07 stderr: Write at 0x0000018b31e8 by goroutine 16:
2025/01/10 14:35:07 stderr: github.com/arduino/arduino-create-agent/systray.(*Systray).SetCurrentConfigFile()
2025/01/10 14:35:07 stderr: /home/dido/code/arduino/arduino-create-agent/systray/systray.go:102 +0x79d
2025/01/10 14:35:07 stderr: main.loop()
2025/01/10 14:35:07 stderr: /home/dido/code/arduino/arduino-create-agent/main.go:261 +0x791
2025/01/10 14:35:07 stderr:
2025/01/10 14:35:07 stderr: Previous write at 0x0000018b31e8 by main goroutine:
2025/01/10 14:35:07 stderr: main.main()
2025/01/10 14:35:07 stderr: /home/dido/code/arduino/arduino-create-agent/main.go:149 +0x239
2025/01/10 14:35:07 stderr:
2025/01/10 14:35:07 stderr: Goroutine 16 (running) created at:
2025/01/10 14:35:07 stderr: main.main()
2025/01/10 14:35:07 stderr: /home/dido/code/arduino/arduino-create-agent/main.go:145 +0xfa
2025/01/10 14:35:07 stderr: ==================
  • What is the new behavior?
    The config is read in the main and the SetCurrentConfigFile on Systray is called by the main goroutine (and not in the other loop go routine)
  • Does this PR introduce a breaking change?
  • Other information:
  • Move the logic to read the config.ini file into the '/config/config.go` module
  • Add Unit tests (only for LINUX OS)
  • Testing the legacy behaviours is not easy (the config.ini file in the old location is copied into the new home location). It relies on the os.Executable() calls

@codecov-commenter
Copy link

codecov-commenter commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 58.97436% with 16 lines in your changes missing coverage. Please review.

Project coverage is 21.59%. Comparing base (1b94ccc) to head (870fac5).

Files with missing lines Patch % Lines
config/config.go 74.19% 7 Missing and 1 partial ⚠️
main.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1012      +/-   ##
==========================================
+ Coverage   20.14%   21.59%   +1.44%     
==========================================
  Files          42       42              
  Lines        3222     3228       +6     
==========================================
+ Hits          649      697      +48     
+ Misses       2488     2442      -46     
- Partials       85       89       +4     
Flag Coverage Δ
unit 21.59% <58.97%> (+1.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Jan 29, 2025
@dido18 dido18 changed the title fix: data race on config concurrent access fix: data race on SetCurrentConfigFile Jan 29, 2025
@dido18 dido18 marked this pull request as ready for review January 29, 2025 13:58
@dido18 dido18 requested a review from a team January 29, 2025 13:58
@dido18 dido18 changed the title fix: data race on SetCurrentConfigFile fix: data race on Systray.SetCurrentConfigFile Jan 29, 2025

Choose a reason for hiding this comment

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

I am not sure which is the difference the configPath is still accessed concurrently by the main thread and in the loop.

Comment on lines +176 to +179
if configPath == nil {
log.Panic("configPath is nil")
}

Choose a reason for hiding this comment

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

configPath should always be not nil, can we avoid the check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants