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: datarace config read/write by multiple go routines #1011

Closed
wants to merge 22 commits into from
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aff40ab
WIP: print to understand
dido18 Jan 10, 2025
bae632a
refactor: remove unused Bufferflow implementations and simplify buffe…
dido18 Jan 10, 2025
818f79f
refactor: simplify serial test functions by removing unused parameters
dido18 Jan 10, 2025
baf2ff4
fix(ci): update package installation command to use correct version o…
dido18 Jan 10, 2025
e63527a
fix(ci): update libwebkit2gtk version in dependency installation
dido18 Jan 10, 2025
98b6376
fix: remove unused buffer slice and simplify data reading in serial port
dido18 Jan 10, 2025
0ce39a5
small changes
dido18 Jan 10, 2025
ec5049d
fix: remove debug print statement from wsHandler function
dido18 Jan 13, 2025
2fe3c28
fix: add warning log for unexpected arguments in open command
dido18 Jan 13, 2025
1849a1c
Update hub.go
dido18 Jan 13, 2025
294de02
fix: update log message for buffer flow initialization
dido18 Jan 14, 2025
99a31e6
fix: update log message for clarity in buffer flow initialization
dido18 Jan 14, 2025
2308b5f
fix: ignore all tags in check-certificates workflow on push
dido18 Jan 14, 2025
8688ec6
fix: update macOS-13 version in publish-go-tester-task workflow
dido18 Jan 14, 2025
894c139
fix(release): add Go installation step in release workflow
dido18 Jan 14, 2025
3a34186
fix: correct JSON formatting in broadcast message for port registration
dido18 Jan 16, 2025
62e324b
Merge branch 'main' into remove-open-not-used-buffer-algorithm
dido18 Jan 17, 2025
92e9536
fix
dido18 Jan 20, 2025
c042f10
fix: update application identity in release workflow to use Massimo B…
dido18 Jan 20, 2025
34d4452
Merge branch 'main' of github.com:arduino/arduino-create-agent into main
dido18 Jan 21, 2025
9d2b0ab
Merge branch 'main' into remove-open-not-used-buffer-algorithm
dido18 Jan 21, 2025
0587f2b
fix
dido18 Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/check-certificates.yml
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ on:
push:
paths:
- ".github/workflows/check-certificates.ya?ml"
tags-ignore:
- '*'
pull_request:
paths:
- ".github/workflows/check-certificates.ya?ml"
9 changes: 7 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -286,6 +286,11 @@ jobs:
-k "${{ env.KEYCHAIN_PASSWORD }}" \
"${{ env.KEYCHAIN }}"

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Install gon for code signing
uses: actions/checkout@v4
with:
@@ -309,7 +314,7 @@ jobs:
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"

sign {
application_identity = "Developer ID Application: ARDUINO SA (7KT7ZWMCJT)"
application_identity = "Massimo Banzi Apple Key"
deep = true
}

@@ -577,7 +582,7 @@ jobs:
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}-installer"

sign {
application_identity = "Developer ID Application: ARDUINO SA (7KT7ZWMCJT)"
application_identity = "Massimo Banzi Apple Key"
}

# Ask Gon for zip output to force notarization process to take place.
23 changes: 0 additions & 23 deletions bufferflow.go

This file was deleted.

72 changes: 0 additions & 72 deletions bufferflow_default.go

This file was deleted.

6 changes: 3 additions & 3 deletions bufferflow_timed.go
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ type BufferflowTimed struct {
bufferedOutput string
}

// NewBufferflowTimed will create a new timed bufferflow
func NewBufferflowTimed(port string, output chan<- []byte) *BufferflowTimed {
// NewBufferFlowTimed will create a new timed bufferflow
func NewBufferFlowTimed(port string, output chan<- []byte) *BufferflowTimed {
return &BufferflowTimed{
port: port,
output: output,
@@ -48,7 +48,7 @@ func NewBufferflowTimed(port string, output chan<- []byte) *BufferflowTimed {

// Init will initialize the bufferflow
func (b *BufferflowTimed) Init() {
log.Println("Initting timed buffer flow (output once every 16ms)")
log.Println("Start consuming from serial port (output once every 16ms)")
go b.consumeInput()
}

89 changes: 0 additions & 89 deletions bufferflow_timedraw.go

This file was deleted.

38 changes: 38 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -142,3 +142,41 @@
}
return nil
}

func GetConfigPath() *paths.Path {

Check failure on line 146 in config/config.go

GitHub Actions / check-style (./)

exported function GetConfigPath should have comment or be unexported
// Let's handle the config
configDir := GetDefaultConfigDir()
var configPath *paths.Path

// see if the env var is defined, if it is take the config from there, this will override the default path
if envConfig := os.Getenv("ARDUINO_CREATE_AGENT_CONFIG"); envConfig != "" {
configPath = paths.New(envConfig)
if configPath.NotExist() {
log.Panicf("config from env var %s does not exists", envConfig)
}
log.Infof("using config from env variable: %s", configPath)
} else if defaultConfigPath := configDir.Join("config.ini"); defaultConfigPath.Exist() {
// by default take the config from the ~/.arduino-create/config.ini file
configPath = defaultConfigPath
log.Infof("using config from default: %s", configPath)
} else {
// Fall back to the old config.ini location
src, _ := os.Executable()
oldConfigPath := paths.New(src).Parent().Join("config.ini")
if oldConfigPath.Exist() {
err := oldConfigPath.CopyTo(defaultConfigPath)
if err != nil {
log.Errorf("cannot copy old %s, to %s, generating new config", oldConfigPath, configPath)
} else {
configPath = defaultConfigPath
log.Infof("copied old %s, to %s", oldConfigPath, configPath)
}
}
}
if configPath == nil {
configPath = GenerateConfig(configDir)
}

return configPath

}
61 changes: 61 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package config

import (
"fmt"
"os"
"testing"

"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestGetConfigPath(t *testing.T) {
t.Run("read config.ini from ARDUINO_CREATE_AGENT_CONFIG", func(t *testing.T) {
os.Setenv("ARDUINO_CREATE_AGENT_CONFIG", "./testdata/fromenv/config.ini")
defer os.Unsetenv("ARDUINO_CREATE_AGENT_CONFIG")
configPath := GetConfigPath()
assert.Equal(t, "./testdata/fromenv/config.ini", configPath.String())
})

t.Run("panic if config.ini does not exist", func(t *testing.T) {
os.Setenv("ARDUINO_CREATE_AGENT_CONFIG", "./testdata/nonexistent_config.ini")
defer os.Unsetenv("ARDUINO_CREATE_AGENT_CONFIG")

defer func() {
if r := recover(); r != nil {
entry, ok := r.(*logrus.Entry)
if !ok {
t.Errorf("Expected panic of type *logrus.Entry but got %T", r)
} else {
assert.Equal(t, "config from env var ./testdata/nonexistent_config.ini does not exists", entry.Message)
}
} else {
t.Errorf("Expected panic but did not get one")
}
}()

GetConfigPath()
})

t.Run("read config.ini from $HOME", func(t *testing.T) {
os.Setenv("HOME", "./testdata/home")
defer os.Unsetenv("HOME")
configPath := GetConfigPath()
assert.Equal(t, "testdata/home/.config/ArduinoCreateAgent/config.ini", configPath.String())
})

t.Run("fallback old : read config.ini where the binary is launched", func(t *testing.T) {
src, _ := os.Executable()
paths.New(src).Parent().Join("config.ini").Create() // create a config.ini in the same directory as the binary
// The fallback path is the directory where the binary is launched
fmt.Println(src)
os.Setenv("HOME", "./testdata/noconfig") // force to not have a config in the home directory
defer os.Unsetenv("HOME")

// expect it creates a config.ini in the same directory as the binary
configPath := GetConfigPath()
assert.Equal(t, "testdata/home/.config/ArduinoCreateAgent/config.ini", configPath.String())
})

}
8 changes: 8 additions & 0 deletions config/testdata/fromenv/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gc = std
hostname = unknown-hostname
regex = usb|acm|com
v = true
appName = CreateAgent/Stable
updateUrl = https://downloads.arduino.cc/
origins = https://local.arduino.cc:8000, https://local.arduino.cc:8001, https://create-dev.arduino.cc, https://*.sparklyunicorn.cc, https://*.iot-cloud-arduino-cc.pages.dev, https://cloud.oniudra.cc, https://app.oniudra.cc,https://*.iot-cloud-arduino-cc.pages.dev
crashreport = false
8 changes: 8 additions & 0 deletions config/testdata/home/.config/ArduinoCreateAgent/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gc = std
hostname = unknown-hostname
regex = usb|acm|com
v = true
appName = config-from-home-dir
updateUrl = https://downloads.arduino.cc/
origins = https://local.arduino.cc:8000, https://local.arduino.cc:8001, https://*.iot-cloud-arduino-cc.pages.dev
crashreport = false
10 changes: 10 additions & 0 deletions config/testdata/noconfig/.config/ArduinoCreateAgent/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
gc = std # Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)
hostname = unknown-hostname # Override the hostname we get from the OS
regex = usb|acm|com # Regular expression to filter serial port list
v = true # show debug logging
appName = CreateAgent/Stable
updateUrl = https://downloads.arduino.cc/
origins = https://local.arduino.cc:8000
#httpProxy = http://your.proxy:port # Proxy server for HTTP requests
crashreport = false # enable crashreport logging
autostartMacOS = true # the Arduino Create Agent is able to start automatically after login on macOS (launchd agent)
Loading