Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race-free Preconditions #935

Merged
merged 5 commits into from
Oct 31, 2022
Merged

Race-free Preconditions #935

merged 5 commits into from
Oct 31, 2022

Conversation

rawler
Copy link
Contributor

@rawler rawler commented Sep 29, 2022

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

@rawler
Copy link
Contributor Author

rawler commented Sep 29, 2022

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
Copy link
Owner

fsouza commented Oct 3, 2022

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
Copy link
Owner

fsouza commented Oct 7, 2022

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

@rawler
Copy link
Contributor Author

rawler commented Oct 12, 2022

@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
Copy link
Owner

fsouza commented Oct 14, 2022

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

@rawler
Copy link
Contributor Author

rawler commented Oct 20, 2022

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
Copy link
Owner

fsouza commented Oct 20, 2022

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!

Copy link
Owner

@fsouza fsouza left a comment

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 🤔

fakestorage/json_response.go Outdated Show resolved Hide resolved
internal/backend/memory.go Outdated Show resolved Hide resolved
fakestorage/upload.go Outdated Show resolved Hide resolved
fakestorage/upload.go Outdated Show resolved Hide resolved
@@ -389,6 +389,50 @@ func TestServerClientObjectOperationsFailureToWriteExistingObject(t *testing.T)
})
}

func TestServerClientUploadRacesAreOnlyWonByOne(t *testing.T) {
const (
Copy link
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
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
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
Copy link
Owner

@fsouza fsouza 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 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants