Skip to content

Commit f86a22f

Browse files
authored
fix(update): increase timeout of core download (#605)
1 parent be1bd9d commit f86a22f

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

internal/update/arduino/arduino.go

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ func NewArduinoPlatformUpdater() *ArduinoPlatformUpdater {
2525
return &ArduinoPlatformUpdater{}
2626
}
2727

28+
func setConfig(ctx context.Context, srv rpc.ArduinoCoreServiceServer) error {
29+
if _, err := srv.SettingsSetValue(ctx, &rpc.SettingsSetValueRequest{
30+
Key: "board_manager.additional_urls",
31+
EncodedValue: "https://arduino:aptexperiment@apt-repo.oniudra.cc/zephyr-core-imola.json",
32+
ValueFormat: "cli",
33+
}); err != nil {
34+
return err
35+
}
36+
if _, err := srv.SettingsSetValue(ctx, &rpc.SettingsSetValueRequest{
37+
Key: "network.connection_timeout",
38+
EncodedValue: "600s",
39+
ValueFormat: "cli",
40+
}); err != nil {
41+
return err
42+
}
43+
44+
return nil
45+
}
46+
2847
// ListUpgradablePackages implements ServiceUpdater.
2948
func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ func(update.UpgradablePackage) bool) ([]update.UpgradablePackage, error) {
3049
if !a.lock.TryLock() {
@@ -34,6 +53,9 @@ func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ f
3453

3554
logrus.SetLevel(logrus.ErrorLevel) // Reduce the log level of arduino-cli
3655
srv := commands.NewArduinoCoreServer()
56+
if err := setConfig(ctx, srv); err != nil {
57+
return nil, err
58+
}
3759

3860
var inst *rpc.Instance
3961
if resp, err := srv.Create(ctx, &rpc.CreateRequest{}); err != nil {
@@ -45,15 +67,6 @@ func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ f
4567
_, _ = srv.Destroy(ctx, &rpc.DestroyRequest{Instance: inst})
4668
}()
4769

48-
_, err := srv.SettingsSetValue(ctx, &rpc.SettingsSetValueRequest{
49-
Key: "board_manager.additional_urls",
50-
EncodedValue: "https://arduino:aptexperiment@apt-repo.oniudra.cc/zephyr-core-imola.json",
51-
ValueFormat: "cli",
52-
})
53-
if err != nil {
54-
return nil, err
55-
}
56-
5770
stream, _ := commands.UpdateIndexStreamResponseToCallbackFunction(ctx, func(curr *rpc.DownloadProgress) {
5871
slog.Debug("Update index progress", slog.String("download_progress", curr.String()))
5972
})
@@ -133,6 +146,15 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
133146
logrus.SetLevel(logrus.ErrorLevel) // Reduce the log level of arduino-cli
134147
srv := commands.NewArduinoCoreServer()
135148

149+
if err := setConfig(ctx, srv); err != nil {
150+
eventsCh <- update.Event{
151+
Type: update.ErrorEvent,
152+
Err: err,
153+
Data: "Error setting additional URLs",
154+
}
155+
return
156+
}
157+
136158
var inst *rpc.Instance
137159
if resp, err := srv.Create(ctx, &rpc.CreateRequest{}); err != nil {
138160
eventsCh <- update.Event{
@@ -153,19 +175,6 @@ func (a *ArduinoPlatformUpdater) UpgradePackages(ctx context.Context, names []st
153175
}()
154176

155177
{
156-
_, err := srv.SettingsSetValue(ctx, &rpc.SettingsSetValueRequest{
157-
Key: "board_manager.additional_urls",
158-
EncodedValue: "https://arduino:aptexperiment@apt-repo.oniudra.cc/zephyr-core-imola.json",
159-
ValueFormat: "cli",
160-
})
161-
if err != nil {
162-
eventsCh <- update.Event{
163-
Type: update.ErrorEvent,
164-
Err: err,
165-
Data: "Error setting additional URLs",
166-
}
167-
return
168-
}
169178
stream, _ := commands.UpdateIndexStreamResponseToCallbackFunction(ctx, downloadProgressCB)
170179
if err := srv.UpdateIndex(&rpc.UpdateIndexRequest{Instance: inst}, stream); err != nil {
171180
eventsCh <- update.Event{

0 commit comments

Comments
 (0)