Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: serialize updateEntitlements()#14974

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/14961-update-entitlements
Oct 5, 2024

Conversation

spikecurtis
Copy link
Contributor

@spikecurtisspikecurtis commentedOct 4, 2024
edited
Loading

fixes#14961

Adding the license and updating entitlements is flaky, especially at the start of ourcoderdent testing because, while the actual modifications to theentitlements.Set were threadsafe, we could have multiple goroutines reading from the database and writing to the set, so we could end up writing stale data.

This enforces serialization on updates, so that if you modify the database and kick off an update, you know the state of theSet is at least as fresh as your database update.

@spikecurtisGraphite App
Copy link
ContributorAuthor

This stack of pull requests is managed by Graphite.Learn more about stacking.

Join@spikecurtis and the rest of your teammates onGraphiteGraphite

@spikecurtisspikecurtis marked this pull request as ready for reviewOctober 4, 2024 12:26
@Emyrk
Copy link
Member

Emyrk commentedOct 4, 2024
edited
Loading

Just so I understand, and jotting notes as I break for a minute. I am going to play with this after some morning calls.

Update (which wasReplace) does an entire entitlements replacement. The multiple go routines callingupdateEntitlements all source from the license in thedb.

Is the issue that in the multiple calls in unit tests, the earlier calls do not have a license. This earlier call happens in parallel to the later call (with license). If the later one finishes first, then the earlier call overwrites it back to no license.

The fix, is to force serialization such that the order of calls toupdateEntitlements is respected. And because the db lookup happens withinupdateEntitlements, if the earlier execution in the previous case is delayed, it's db lookup is also delayed. So it will fetch the latest value.

This looks to be a good solution. The test does not exercise the bug when I remove the channel, but I only briefly looked at it atm.


An aside. when I extracted this logic out into this package, I was not really happy with the API it exposed. But it was already used throughout the codebase, and refactoring it everywhere felt like a large lift.

Since we only have 1 entitlement per coderd, it could probably be it's own go routine and take feature sets to merge into the existing. Ensuring everything is done in order if multiple threads are working with it. Order would matter still though, as there is no time information to know whichFeature should take precedence.

@spikecurtis
Copy link
ContributorAuthor

Is the issue that in the multiple calls in unit tests, the earlier calls do not have a license. This earlier call happens in parallel to the later call (with license). If the later one finishes first, then the earlier call overwrites it back to no license.

Yeah, exactly.

The test does not exercise the bug when I remove the channel, but I only briefly looked at it atm.

Hard to hit the bug consistently, since it's a race over which one writes first.

Copy link
Member

@EmyrkEmyrk left a comment

Choose a reason for hiding this comment

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

Hard to hit the bug consistently, since it's a race over which one writes first.

I figured it would be.


Theentitlements package I refactored out because I had to access it from theidpsync package, and there is an import loop ifentitlements is kept incoderd.

I think if done from scratch, the update code would look a lot different.

Regardless, I like this serialized approach.Modify can still get around this, but it's really useful for unit tests.

@spikecurtisspikecurtis merged commit288df75 intomainOct 5, 2024
31 checks passed
@spikecurtisspikecurtis deleted the spike/14961-update-entitlements branchOctober 5, 2024 02:58
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsOct 5, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@EmyrkEmyrkEmyrk approved these changes

Assignees

@spikecurtisspikecurtis

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

flake: TestProxyRegisterDeregister
2 participants
@spikecurtis@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp