arduino-create-agent icon indicating copy to clipboard operation
arduino-create-agent copied to clipboard

fix: data race on `Systray.SetCurrentConfigFile`

Open dido18 opened this issue 10 months ago • 1 comments
trafficstars

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

dido18 avatar Jan 21 '25 09:01 dido18