arduino-create-agent
arduino-create-agent copied to clipboard
fix: data race on `Systray.SetCurrentConfigFile`
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
SetCurrentConfigFilemethod 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
SetCurrentConfigFileon Systray is called by the main goroutine (and not in the otherloopgo 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
legacybehaviours is not easy (the config.ini file in the old location is copied into the new home location). It relies on theos.Executable()calls