Skip to content

azure: concurrent writes result in 404s or corrupted blobs #2077

Closed

Description

@ahmetb

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.

cc: @yuwaMSFT

Activity

  1. stevvooe commented on Nov 21, 2016

    @stevvooe
    Collaborator

    @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.

  2. ahmetb commented on Nov 22, 2016

    @ahmetb
    ContributorAuthor

    @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.

  3. added this to the milestone on Nov 22, 2016
  4. stevvooe commented on Nov 23, 2016

    @stevvooe
    Collaborator

    @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?

  5. yuwaMSFT2 commented on Nov 23, 2016

    @yuwaMSFT2
    Contributor

    @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.

  6. stevvooe commented on Nov 24, 2016

    @stevvooe
    Collaborator

    @yuwaMSFT2 I see. It sounds like PutContent needs to be more atomic.

    Let's see a PR! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions