Skip to content

Race-free Preconditions - #935

Merged
fsouza merged 5 commits into
fsouza:mainfrom
rawler:race-free-preconditions
Oct 31, 2022
Merged

Race-free Preconditions#935
fsouza merged 5 commits into
fsouza:mainfrom
rawler:race-free-preconditions

Conversation

@rawler

@rawler rawler commented Sep 29, 2022

Copy link
Copy Markdown
Contributor

This fixes an issue we've experienced, where "IfNotExist"-style uploads have exhibited racy behavior, specified to not exist in production GCS.

@rawler

rawler commented Sep 29, 2022

Copy link
Copy Markdown
Contributor Author

Apologies in advance for my lack of Go experience. I'm sure much of this patch is non-idiomatic, and it is submitted as much as a basis for discussion, as an actual proposal.

@fsouza

fsouza commented Oct 3, 2022

Copy link
Copy Markdown
Owner

Thank you for contributing! I'll take a look at this change over the next couple of days, but there's definitely no reason to apologize, if anything in the code needs improvements, we'll work on it!

@fsouza

fsouza commented Oct 7, 2022

Copy link
Copy Markdown
Owner

@rawler can you take a look at the build failure?

@rawler

rawler commented Oct 12, 2022

Copy link
Copy Markdown
Contributor Author

@rawler can you take a look at the build failure?

I looked into them, but I don't understand how it's caused by what I did. From what I see, the cause seems to be:

bucket_test.go:278: rename C:\Users\RUNNER~1\AppData\Local\Temp\fakestorage-test-root-1941404170\some-bucket\fake-gcs-object3621328271 C:\Users\RUNNER~1\AppData\Local\Temp\fakestorage-test-root-1941404170\some-bucket\img%2Fhi-res%2Fparty-01.jpg: Access is denied.

@fsouza

fsouza commented Oct 14, 2022

Copy link
Copy Markdown
Owner

@rawler ugh ok, I'll dig into that. Thank you for your patience!

@rawler

rawler commented Oct 20, 2022

Copy link
Copy Markdown
Contributor Author

Any time to work on this? Let me know if I can contribute in any way.

I'm not blocked by this, but carrying a fork that I'd love to clean up :)

@fsouza

fsouza commented Oct 20, 2022

Copy link
Copy Markdown
Owner

Hey, sorry, things have been a bit busy on my side, but I believe I'll have a chance to look into it (both the test failure and review the code) this weekend.

Thank you very much for your contribution and your patience!

@fsouza fsouza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Code looks sane. I'm not sure if things will work in the filesystem backend. Also I feel like at some point we should refactor generations out of the backends, but not a blocker for this PR.

I'm trying to figure out the issue with the CI on Windows, but it's quite cryptic 🤔

Comment thread fakestorage/json_response.go Outdated
Comment thread internal/backend/memory.go Outdated
Comment thread fakestorage/upload.go Outdated
Comment thread fakestorage/upload.go Outdated
}

func TestServerClientUploadRacesAreOnlyWonByOne(t *testing.T) {
const (

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you use runServersTest to make sure we're testing both backends?

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.

Sure! I worried a little bit about test-performance, given that this test is trying to provoke a race, therefor running multiple iterations. However, I think perhaps we could tune down repetitions slightly to compensate. Attaching test-durations from my machine below.

Also pushing a small improvement in test-diagnostics. On conflict, the test will now describe the conflict in more detail.

ok github.com/fsouza/fake-gcs-server 0.016s
ok github.com/fsouza/fake-gcs-server/fakestorage 1.176s
ok github.com/fsouza/fake-gcs-server/internal/backend 0.031s
ok github.com/fsouza/fake-gcs-server/internal/checksum 0.010s
ok github.com/fsouza/fake-gcs-server/internal/config 0.010s
ok github.com/fsouza/fake-gcs-server/internal/notification 0.026s

@fsouza fsouza mentioned this pull request Oct 30, 2022
rawler and others added 5 commits October 31, 2022 15:01
This tests for race-conditions in Conditional uploads, by repeatedly
uploading to the same object from multiple go-routines, and verify that
only one succeeded.
Move the "Preconditions"-checking into the backend, to be done under the
protection of the backend mutex. This enables `DoesNotExist`-behavior to be
implemented race-free
Co-authored-by: fsouza <108725+fsouza@users.noreply.github.com>
While potentially a problem for test-performance, speed of running tests
are currently bearable on my machine

ok  	github.com/fsouza/fake-gcs-server	0.016s
ok  	github.com/fsouza/fake-gcs-server/fakestorage	1.176s
ok  	github.com/fsouza/fake-gcs-server/internal/backend	0.031s
ok  	github.com/fsouza/fake-gcs-server/internal/checksum	0.010s
ok  	github.com/fsouza/fake-gcs-server/internal/config	0.010s
ok  	github.com/fsouza/fake-gcs-server/internal/notification	0.026s
@rawler
rawler force-pushed the race-free-preconditions branch from 4519b45 to 4aba11a Compare October 31, 2022 14:26

@fsouza fsouza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for contributing. I'll simply merge this and drop support for Windows. It's simply not possible to safely rename files on Windows, and I don't expect a lot of people to be using fake-gcs-server on Windows (they can always use WSL or Docker).

@fsouza
fsouza merged commit 4e828df into fsouza:main Oct 31, 2022
@rawler
rawler deleted the race-free-preconditions branch November 8, 2022 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants