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

Remove incorrect use of TryLock for initial delay state in TUF autoupdater #1676

Merged
merged 4 commits into from Apr 10, 2024

Conversation

RebeccaMahany
Copy link
Contributor

@RebeccaMahany RebeccaMahany commented Apr 9, 2024

I didn't add TryLock correctly here before -- this had the consequence that a request to pin a version or autoupdate immediately outside of the initial delay would then block subsequent requests to pin a version or autoupdate immediately.

In this PR, I've pulled it out in favor of a timestamp; we set the timestamp in NewTufAutoupdater rather than in Execute to avoid data races in tests (or a mutex added only to address data races in tests).

Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably okay, but since our only usage is:

	if ta.isInInitialDelay() {
		ta.slogger.Log(context.TODO(), slog.LevelWarn,
			"received update request during initial delay, discarding",
		)
		// 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
	}

I'd rather move away from mutexes and all all the potential locks. What if we recorded the time we should be locked until, and then time compared? I guess that fails if the clock is updated mid delay.

I guess one approach would be to keep our own program runtime. But that feels like a lot of work.

So maybe this is the simplest approach

@RebeccaMahany
Copy link
Contributor Author

@directionless I like that idea too, but setting something like ta.initialDelayEnd = time.Now().Add(ta.knapsack.AutoupdateInitialDelay()) at the beginning of Execute will still require a mutex to avoid data races during the tests 😕 -- that's the only reason I preserved the mutex.

@RebeccaMahany RebeccaMahany marked this pull request as ready for review April 9, 2024 21:08
zackattack01
zackattack01 previously approved these changes Apr 9, 2024
James-Pickett
James-Pickett previously approved these changes Apr 9, 2024
@directionless
Copy link
Contributor

@directionless I like that idea too, but setting something like ta.initialDelayEnd = time.Now().Add(ta.knapsack.AutoupdateInitialDelay()) at the beginning of Execute will still require a mutex to avoid data races during the tests 😕 -- that's the only reason I preserved the mutex.

Hrm... If we set it at create time, we could skip the mutex... Might not be worth it. Fun thought exercise

@RebeccaMahany RebeccaMahany added this pull request to the merge queue Apr 10, 2024
Merged via the queue into kolide:main with commit 2111d34 Apr 10, 2024
31 checks passed
@RebeccaMahany RebeccaMahany deleted the becca/tuf-trylock-remove branch April 10, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants