Skip to content

chore: remove duplicate validate calls on same oauth token - #11598

Merged
Emyrk merged 3 commits into
mainfrom
stevenmasley/validate_debounce
Jan 12, 2024
Merged

Emyrk merged 3 commits into
mainfrom
stevenmasley/validate_debounce

Conversation

@Emyrk

@Emyrk Emyrk commented Jan 12, 2024 •

Copy link
Copy Markdown
Member

What this does

If we have an invalid token in the db, we should not spam github with the same validate call over and over.

I am not sure how often this was hit in production, since most keys that go invalid expire, which we already check for.

This happens if someone manually revokes a token.

Related to #10853

Thoughts

I think this should really be solved more generally. We should remember when a token is invalid, and not try again. The browser and other things also trigger this call, which we could deduplicate with a cache.

This would save some calls in all cases.

The metrics indicate we are potentially sending more calls from TokenSource thenValidate though.

@Emyrk
Emyrk requested a review from johnstcn January 12, 2024 20:07
Comment thread coderd/coderd.go
Comment on lines +214 to +219
if options.NewTicker == nil {
options.NewTicker = func(duration time.Duration) (tick <-chan time.Time, done func()) {
ticker := time.NewTicker(duration)
return ticker.C, ticker.Stop
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is OK for now but we should probably swap this out for something better later on 🕰️

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree. Some fake clock solution would be ideal, then we can use across all tests more generally.

@Emyrk
Emyrk merged commit 03ee639 into main Jan 12, 2024
@Emyrk
Emyrk deleted the stevenmasley/validate_debounce branch January 12, 2024 20:27
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants