Skip to content

Fix TestHeadlessAuthenticationWatcher flakiness#24562

Merged
Joerger merged 4 commits intomasterfrom
joerger/fix-headless-authn-watcher-stale-race-condition
Apr 17, 2023
Merged

Fix TestHeadlessAuthenticationWatcher flakiness#24562
Joerger merged 4 commits intomasterfrom
joerger/fix-headless-authn-watcher-stale-race-condition

Conversation

@Joerger
Copy link
Copy Markdown
Contributor

@Joerger Joerger commented Apr 13, 2023

After repeatedly getting TestHeadlessAuthenticationWatcher flakiness and mistakenly just shifting the problem around, I decided this time to restructure the headless watcher and subscriber logic to make testing without race conditions possible.

For context, the headless authentication watcher uses a stale channel to skip slow subscribers. Subscribers are expected to watch the stale channel and check the backend on receive. This PR breaks out this logic from the single headlessAuthenticationWatcher.Wait method into a new HeadlessAuthenticationSubscriber interface. This interface gives tests more insight into the stale mechanism, etc, without creating // Only used in tests backdoors into the watcher.

This change also makes the TestHeadlessAuthenticationWatcher much faster 🚀 since it avoids unstable waiting/ticking logic.

Closes #24409

Copy link
Copy Markdown
Contributor

@mdwn mdwn left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me. I've got two questions, but feel free to push back on these.

Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
Copy link
Copy Markdown
Contributor

@codingllama codingllama left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, Brian!

Comment thread lib/auth/auth.go Outdated
Comment thread lib/auth/methods.go
Comment thread lib/services/local/headlessauthn_watcher.go Outdated
select {
case t := <-h.retry.After():
h.Log.Debugf("Attempting to restart watch after waiting %v.", t.Sub(startedWaiting))
h.Log.Warningf("Restarting watch on error after waiting %v. Error: %v.", t.Sub(startedWaiting), err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does h.watch always return a non-nil error? I'm a bit confused by the error handling here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, h.watch should always return non-nil error, and we want to restart the watcher on any error received, unless it's a context canceled/deadline error or the watcher is closed, which is covered by the select case.

Comment thread lib/services/local/headlessauthn_watcher.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
@Joerger Joerger requested review from codingllama and mdwn April 14, 2023 20:37
Copy link
Copy Markdown
Collaborator

@zmb3 zmb3 left a comment

Choose a reason for hiding this comment

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

I like the new approach. See comments for some minor suggestions.

Comment thread lib/services/local/headlessauthn_watcher.go Outdated
Comment thread lib/services/local/headlessauthn_watcher_test.go Outdated
@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from nklaassen April 17, 2023 15:04
@Joerger Joerger enabled auto-merge April 17, 2023 20:19
@Joerger Joerger added this pull request to the merge queue Apr 17, 2023
Merged via the queue into master with commit 9f5a81b Apr 17, 2023
@Joerger Joerger deleted the joerger/fix-headless-authn-watcher-stale-race-condition branch April 17, 2023 20:51
@public-teleport-github-review-bot
Copy link
Copy Markdown

@Joerger See the table below for backport results.

Branch Result
branch/v12 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TestHeadlessAuthenticationWatcher flakiness

4 participants