Skip to content

Locking implementation does not appear to be atomic #3

@mholt

Description

@mholt

Thanks for making this implementation for CertMagic!

It came up in the Gophers Slack today that this implementation may not be atomic; specifically the existence check and the creation are racey between multiple instances:

magicstorage/s3storage.go

Lines 246 to 254 in 0c0f14c

exists := s.Exists(filename)
if exists {
return fmt.Errorf(lockFileExists)
}
_, err := s.svc.PutObject(&s3.PutObjectInput{
Bucket: s.bucket,
Key: aws.String(filename),
Body: bytes.NewReader([]byte("lock")),
})

I'm not sure that S3 provides atomic operations at all; however, maybe some use of DynamoDB could be made to provide proper locking?

I was pointed to Terraform, which uses S3 for storage - I have not vetted its implementation but just wanted to include the link for reference, in case it's helpful: https://github.com/hashicorp/terraform/tree/master/backend/remote-state/s3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions