fix: resolve CORS cache race condition causing stale 404 responses (#8748)
The metadata subscription handler (updateBucketConfigCacheFromEntry) was making a separate RPC call via loadCORSFromBucketContent to load CORS configuration. This created a race window where a slow CreateBucket subscription event could re-cache stale data after PutBucketCors had already cleared the cache, causing subsequent GetBucketCors to return 404 NoSuchCORSConfiguration. Parse CORS directly from the subscription entry's Content field instead of making a separate RPC. Also fix getBucketConfig to parse CORS from the already-fetched entry, eliminating a redundant RPC call. Fix TestCORSCaching to use require.NoError to prevent nil pointer dereference panics when GetBucketCors fails.
This commit is contained in:
@@ -590,17 +590,14 @@ func TestCORSCaching(t *testing.T) {
|
||||
Bucket: aws.String(bucketName),
|
||||
CORSConfiguration: corsConfig1,
|
||||
})
|
||||
assert.NoError(t, err, "Should be able to put initial CORS configuration")
|
||||
|
||||
// Wait for metadata subscription to update cache
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
require.NoError(t, err, "Should be able to put initial CORS configuration")
|
||||
|
||||
// Get the configuration
|
||||
getResp1, err := client.GetBucketCors(context.TODO(), &s3.GetBucketCorsInput{
|
||||
Bucket: aws.String(bucketName),
|
||||
})
|
||||
assert.NoError(t, err, "Should be able to get initial CORS configuration")
|
||||
assert.Len(t, getResp1.CORSRules, 1, "Should have one CORS rule")
|
||||
require.NoError(t, err, "Should be able to get initial CORS configuration")
|
||||
require.Len(t, getResp1.CORSRules, 1, "Should have one CORS rule")
|
||||
|
||||
// Update the configuration
|
||||
corsConfig2 := &types.CORSConfiguration{
|
||||
@@ -618,17 +615,14 @@ func TestCORSCaching(t *testing.T) {
|
||||
Bucket: aws.String(bucketName),
|
||||
CORSConfiguration: corsConfig2,
|
||||
})
|
||||
assert.NoError(t, err, "Should be able to update CORS configuration")
|
||||
|
||||
// Wait for metadata subscription to update cache
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
require.NoError(t, err, "Should be able to update CORS configuration")
|
||||
|
||||
// Get the updated configuration (should reflect the changes)
|
||||
getResp2, err := client.GetBucketCors(context.TODO(), &s3.GetBucketCorsInput{
|
||||
Bucket: aws.String(bucketName),
|
||||
})
|
||||
assert.NoError(t, err, "Should be able to get updated CORS configuration")
|
||||
assert.Len(t, getResp2.CORSRules, 1, "Should have one CORS rule")
|
||||
require.NoError(t, err, "Should be able to get updated CORS configuration")
|
||||
require.Len(t, getResp2.CORSRules, 1, "Should have one CORS rule")
|
||||
|
||||
rule := getResp2.CORSRules[0]
|
||||
assert.Equal(t, []string{"Content-Type"}, rule.AllowedHeaders, "Should have updated headers")
|
||||
|
||||
Reference in New Issue
Block a user