You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
azure: concurrent writes result in 404s or corrupted blobs #2077
Summary: The azure storagedriver currently results often in blob not found or manifest blob not found errors (HTTP 404) (and theoretically can result in corrupted blobs) when multiple clients concurrently operate on the same blob (i.e. the same layer), due to the lack of concurrency safeguards in the code.
Prior to #1438, azure storagedriver used to allow concurrent clients to work on the same blob, and at the end we had a CommitBlockBlob call, which atomically submits the blocks (parts) of a blob to have a consistent picture at the end. So we used to let multiple clients go through with "last writer wins".
The pull request #1438 landed a new writer/blockWriter implementation doesn't use any lock primitives (such as UploadID in s3-aws driver or Session-ID in gcr driver). This causes race issues when multiple clients work on the same blob, namely:
some clients observe 404s because we do some client-side DeleteBlob()s
we may end up with corrupted blobs as multiple clients can call AppendBlock() simultaneously.
We can't switch back to the old implementation because we used to use BlockBlobs and #1438 uses AppendBlobs (these two are not compatible/interchangeable). So the existing registries would be broken. Also the new AppendBlobs are easier to work with anyway, the current implementation is simpler and more efficient. It just lacks the concurrency safety.
Azure doesn't have a concept of Upload Sessions. The closest we can do is to use blob leases. This puts a lock on the blob (with a TTL) for write operations.
This way, concurrent clients (or when the registry crashes and comes back and the client retries), the registry API will return an error response from Azure Blob Storage backend saying there's a lock on the blob.
I'm not sure how s3/gcs drivers handle concurrent writers operating on the same blob (any input here is most appreciated). I will work on prototyping using Blob Leases in all operations and stress the registry and probably measure the API QoS in this situation.
@ahmetalpbalkan So, the basic requirement of Move is that it is atomic or it is made to behave atomically.
My guess is that perhaps, FileWriter.Commit isn't doing a strong enough check? It looks like all it does is flush. Ideally, it should coalesce data and prepare for an atomic move.
@stevvooe Chatted with Derek on IRC for a bit. It appears like in this case, I believe the race is coming from PutContent() and not registry blobwriter using the driver.Writer().
PutContent() uses the azure#writer type, which is not safe for concurrent use. It looks like when we stress the registry, concurrent calls to PutContent(ctx,path,data) with the same path cause corruption/404s because multiple callers step on each other.
The solution appears to be doing an atomic Put Blob operation here (as we used to do). It can upload at most 4 MB, which seems OK here, since PutContent() is designed for small blobs. I'll work more on this. Just opened this issue to keep track of things.
@ahmetalpbalkan No clients should be able to write to the same blob, unless they share their upload UUID. Is this a realistic test?
Looking at the current implement of PutContent, indeed that is quite racy, with a Delete in there.
However, I am not convinced this is the issue. Do you have more data isolating this problem? Have we isolated this to a particular storage driver operation? Which API calls are being exercised in the test?
@stevvooe The test is pretty simple. Just many clients initiate concurrent layer uploading at the same time (POST/PATCH/PUT). Some of them uploads the same layer (the same content with the same SHA) of the same repo.
Uploading is fine as you mentioned they are uploading to individual paths. The problem is the final commit, which would potentially write to the same destination. In the case we saw it is the link file of the layer. This is the sequence of the operation of the failed layer commit from our log:
(*blobWriter).Commit
azure.PutContent(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/hashstates/sha256/0)
azure.Stat(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/data)
azure.List(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/hashstates/sha256)
azure.GetContent(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/hashstates/sha256/1000)
azure.Stat(/docker/registry/v2/blobs/sha256/54/541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53/data)
azure.PutContent(/docker/registry/v2/repositories/stressapp1472427/_layers/sha256/541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53/link)
unknown error completing upload: azure: storage: service returned error: StatusCode=404, ErrorCode=BlobNotFound, ErrorMessage=The specified blob does not exist.
Activity
stevvooe commentedon Nov 21, 2016
@ahmetalpbalkan So, the basic requirement of
Moveis that it is atomic or it is made to behave atomically.My guess is that perhaps,
FileWriter.Commitisn't doing a strong enough check? It looks like all it does is flush. Ideally, it should coalesce data and prepare for an atomic move.ahmetb commentedon Nov 22, 2016
@stevvooe Chatted with Derek on IRC for a bit. It appears like in this case, I believe the race is coming from
PutContent()and not registry blobwriter using thedriver.Writer().PutContent()uses theazure#writertype, which is not safe for concurrent use. It looks like when we stress the registry, concurrent calls toPutContent(ctx,path,data)with the samepathcause corruption/404s because multiple callers step on each other.The solution appears to be doing an atomic Put Blob operation here (as we used to do). It can upload at most 4 MB, which seems OK here, since
PutContent()is designed for small blobs. I'll work more on this. Just opened this issue to keep track of things.stevvooe commentedon Nov 23, 2016
@ahmetalpbalkan No clients should be able to write to the same blob, unless they share their upload UUID. Is this a realistic test?
Looking at the current implement of
PutContent, indeed that is quite racy, with a Delete in there.However, I am not convinced this is the issue. Do you have more data isolating this problem? Have we isolated this to a particular storage driver operation? Which API calls are being exercised in the test?
yuwaMSFT2 commentedon Nov 23, 2016
@stevvooe The test is pretty simple. Just many clients initiate concurrent layer uploading at the same time (POST/PATCH/PUT). Some of them uploads the same layer (the same content with the same SHA) of the same repo.
Uploading is fine as you mentioned they are uploading to individual paths. The problem is the final commit, which would potentially write to the same destination. In the case we saw it is the link file of the layer. This is the sequence of the operation of the failed layer commit from our log:
(*blobWriter).Commit
azure.PutContent(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/hashstates/sha256/0)
azure.Stat(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/data)
azure.List(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/hashstates/sha256)
azure.GetContent(/docker/registry/v2/repositories/stressapp1472427/_uploads/6d4cb124-bfd9-462c-acd4-592d1bd87c33/hashstates/sha256/1000)
azure.Stat(/docker/registry/v2/blobs/sha256/54/541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53/data)
azure.PutContent(/docker/registry/v2/repositories/stressapp1472427/_layers/sha256/541b3e9daa09b20bf85fa273e5cbd3e80185aa4ec298e765db87742b70138a53/link)
unknown error completing upload: azure: storage: service returned error: StatusCode=404, ErrorCode=BlobNotFound, ErrorMessage=The specified blob does not exist.
stevvooe commentedon Nov 24, 2016
@yuwaMSFT2 I see. It sounds like
PutContentneeds to be more atomic.Let's see a PR! 😃
azure: fix race condition in PutContent()