This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Check Last ID when updating site config to prevent race conditions#42691
Merged
Check Last ID when updating site config to prevent race conditions#42691
Conversation
kopancek
approved these changes
Oct 7, 2022
Co-authored-by: Milan Freml <kopancek@users.noreply.github.com>
mrnugget
reviewed
Oct 7, 2022
Comment on lines
+33
to
+36
| confStore.SiteGetLatestFunc.SetDefaultReturn( | ||
| &database.SiteConfig{ID: 1}, | ||
| nil, | ||
| ) |
Contributor
There was a problem hiding this comment.
Suggested change
| confStore.SiteGetLatestFunc.SetDefaultReturn( | |
| &database.SiteConfig{ID: 1}, | |
| nil, | |
| ) | |
| confStore.SiteGetLatestFunc.SetDefaultReturn(&database.SiteConfig{ID: 1}, nil) |
Comment on lines
+42
to
+48
| err := confSource.Write(context.Background(), conftypes.RawUnified{}, 0) | ||
| assert.Error(t, err) | ||
| }) | ||
|
|
||
| t.Run("no error when correct last ID", func(t *testing.T) { | ||
| err := confSource.Write(context.Background(), conftypes.RawUnified{}, 1) | ||
| assert.NoError(t, err) |
Contributor
There was a problem hiding this comment.
Nitpick (!!!): instead of using literal values like 0 and 1 here I'd reference the correct value and/or give names to the wrong values, just so it's clear what the test is doing. Granted (that's why I wrote "Nitpick") in this case it is pretty clear, but still:
conf := &database.SiteConfig{ID: 1}
// [...]
err := confSource.Write(context.Background(), conftypes.RawUnified{}, conf.ID+9999)
// [...]
err := confSource.Write(context.Background(), conftypes.RawUnified{}, conf.ID)that's what I would write
mrnugget
approved these changes
Oct 7, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves #35428
Adds a check when making Site Config updates to ensure that race conditions don't occur. The Last ID, which is supplied alongside a site config update, is used to determine if a site config update happened before this update was attempted.
See Loom for demonstration in UI: https://www.loom.com/share/f315821af6af4c11ba333f294a81d57f
Test plan
Unit tests and manual testing