Repository navigation
Conversation
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## zimeg-feat-auto-update-record #807 +/- ##
=================================================================
- Coverage 80.15% 79.95% -0.20%
=================================================================
Files 245 246 +1
Lines 18949 18790 -159
=================================================================
- Hits 15189 15024 -165
- Misses 3760 3766 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Looks good overall. One design point before approving: the lock only guards Nits: |
| } | ||
| // The lock is an OS file lock, so it's released if this process exits early. The lock file | ||
| // stays on disk, since removing it could let another update lock a new file at the same path. | ||
| lock := flock.New(filepath.Join(configDir, autoUpdateLockFileName)) |
There was a problem hiding this comment.
suggestion (non-blocking): Since the lock lives in the config dir, two commands with different --config-dir values could both swap the same binary, and slack upgrade installs without taking it. Maybe lock next to the binary and take it in slack upgrade too, here or in a follow-up?
|
|
||
| // newDownloadClient returns the HTTP client that downloads the CLI | ||
| func newDownloadClient() *http.Client { | ||
| return &http.Client{Timeout: downloadTimeout} |
There was a problem hiding this comment.
suggestion (non-blocking): Timeout covers reading the whole body too, so a working slack upgrade download slower than about 50 KB/s fails at 10 minutes. A ResponseHeaderTimeout plus a stall deadline might catch the hung case without cutting off slow connections.
WilliamBergamin
left a comment
There was a problem hiding this comment.
🔒 Thanks @zimeg! Checking the lock from inside the install stub is a really clean way to prove the critical section.
One blocking comment on a back-to-back reinstall, the rest are optional or can move to the next PR 🙏
- : 🔭 suggestion (non-blocking): The interactive self-update still calls
slack-cli/internal/update/update.go
Line 91 in 1c65529
InstallUpdatewithout the lock, so once the background command lands it can race anAutoUpdatein another terminal. Worth taking the same lock here, in this PR or the next.
| _ = lock.Unlock() | ||
| }() | ||
|
|
||
| cli := NewCLIDependency(clients, currentVersion) |
There was a problem hiding this comment.
🧠 issue (blocking): The lock stops overlapping installs, but not one that starts right after another finishes. A process still on the old version takes the freed lock, installs the same target again, and backupBinary files the new binary under backups/<old version>, replacing the real backup. Could we check under the lock whether the target is already installed (or already recorded) and skip, with a test for that sequential case?
|
|
||
| // downloadTimeout limits how long a download of the CLI can take, so a stalled download | ||
| // doesn't hold the update lock or keep a background update running | ||
| const downloadTimeout = 10 * time.Minute |
There was a problem hiding this comment.
🤔 suggestion (non-blocking): This timeout also bounds slack upgrade, and http.Client.Timeout includes reading the body, so a slow link that used to finish now fails at 10 minutes. Passing ctx into download with http.NewRequestWithContext and letting the background command set the deadline would leave the interactive path as it was.
| } | ||
|
|
||
| // newDownloadClient returns the HTTP client that downloads the CLI | ||
| func newDownloadClient() *http.Client { |
There was a problem hiding this comment.
🪞 suggestion (non-blocking): The package already builds clients with api.NewHTTPClient (update.go). Using it here with TotalTimeOut: 10 * time.Minute keeps one way to make a client.
| } | ||
| } | ||
|
|
||
| func Test_newDownloadClient(t *testing.T) { |
There was a problem hiding this comment.
🧪 suggestion (non-blocking): This checks the client's field, but it would still pass if download stopped using newDownloadClient. Calling download against an httptest server would cover the real path.
| if err != nil { | ||
| return err | ||
| } | ||
| // The lock is an OS file lock, so it's released if this process exits early. The lock file |
There was a problem hiding this comment.
🪓 suggestion (non-blocking): The doc and inline comments here mostly restate the names. The lock-file note is a real invariant, so a test that the file stays after unlock would hold it better than prose.
| assert.Equal(t, "4.12.0", c.releaseInfo.Version) | ||
| locked, err := flock.New(lockPath).TryLock() | ||
| require.NoError(t, err) | ||
| assert.False(t, locked, "the lock is held while installing") |
There was a problem hiding this comment.
💯 praise: Asserting the lock is held from inside the install stub proves the critical section, not just the outcome.
Changelog
N/A, groundwork for the
auto-updateexperiment.Summary
This pull request adds
update.AutoUpdate, which installs a CLI update while holding a lock and records the result for the next command to report.AutoUpdatetakes an OS file lock onautoupdate.lockin the Slack config directory withgithub.com/gofrs/flock. If another update holds it, it returns right away without installing or recording anything, so two terminals finishing commands at the same moment install once.vprefix, plus the error when the install fails. The install error is returned so it reaches the log.gofrs/flockwas already an indirect dependency and is now a direct one.AutoUpdateyet: the hidden command that runs it in the background comes next.Preview
N/A, nothing changes for developers yet.
Testing
N/A, nothing calls
AutoUpdateyet. The unit tests record the new version after installing, record and return the error when the install fails, skip without installing or recording while a second lock holder has the lock, hold the lock during the install and release it afterwards, and check the download timeout.Notes
clients.Fs, since an OS lock needs a file descriptor. The tests use a temporary directory as the config directory for this reason.slack upgrade, which had no timeout before.GOOS=windows go build ./...compiles:flockusesLockFileExthere.Requirements
🤖 Generated with Claude Code