Skip to content

Commit

Permalink
Discard "update now" requests during initial autoupdate delay (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Mar 7, 2024
1 parent eb6e451 commit 6e04b1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ee/tuf/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@ func (ta *TufAutoupdater) Interrupt(_ error) {
func (ta *TufAutoupdater) Do(data io.Reader) error {
if !ta.initialDelayLock.TryLock() {
ta.slogger.Log(context.TODO(), slog.LevelWarn,
"received update request during initial delay",
"received update request during initial delay, discarding",
)
return errors.New("cannot perform update during initial delay")
// We don't return an error because there's no need for the actionqueue to retry this request --
// we're going to perform an autoupdate check as soon as we exit the delay anyway.
return nil
}

var updateRequest controlServerAutoupdateRequest
Expand Down
4 changes: 2 additions & 2 deletions ee/tuf/autoupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,12 @@ func TestDo_WillNotExecuteDuringInitialDelay(t *testing.T) {
// Start the autoupdater, then make the control server request right away, during the initial delay
go autoupdater.Execute()
time.Sleep(100 * time.Millisecond)
require.Error(t, autoupdater.Do(data), "expected error making request during initial delay")
require.NoError(t, autoupdater.Do(data), "should not have received error when performing request during initial delay")

// Give autoupdater a chance to run
time.Sleep(initialDelay + interval)

// Assert expectation that we added the expected `testReleaseVersion` to the updates library
// Assert expectation that we did not add the expected `testReleaseVersion` to the updates library
mockLibraryManager.AssertExpectations(t)

// Confirm we pulled all config items as expected
Expand Down

0 comments on commit 6e04b1e

Please sign in to comment.