diff --git a/internal/aws/s3/s3.go b/internal/aws/s3/s3.go index 01b36983..91535a58 100644 --- a/internal/aws/s3/s3.go +++ b/internal/aws/s3/s3.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "path/filepath" + "time" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" @@ -199,6 +200,34 @@ func RainBucket(forceCreation bool) string { } } + // Sleep for 2 seconds to give the bucket time to stabilize + time.Sleep(2 * time.Second) + + // #213 + // Confirm that the bucket really does exist. + // Seems unnecessary but bug 213 looks like a race condition. Maybe + // checking here and pausing a few seconds will be enough? + isBucketExists, err = BucketExists(bucketName) + if err != nil { + config.Debugf("unable to confirm bucket after creation: %v", err) + } + + if !isBucketExists { + // Sleep for 5 seconds + time.Sleep(5 * time.Second) + + // Check again + isBucketExists, err = BucketExists(bucketName) + if err != nil { + panic(fmt.Errorf("unable to re-confirm whether artifact bucket exists: %w", err)) + } + + // Give up + if !isBucketExists { + panic(fmt.Errorf("cannot confirm that artifact bucket '%s' exists", bucketName)) + } + } + return bucketName }