Regression of negative content-length support #486

Closed
opened 2024-09-10 11:14:45 +00:00 by alexvanin · 0 comments
Owner

Expected Behavior

Negative or omitted content-length does not affect size attribute of the object, it sets according to the size of processed payload (#125)

Current Behavior

Cached value contains correct size, but tree node does not.

Possible Solution

Use createdObject.Size instead of p.Size here.

It might affect SSE, need to investigate more.

Steps to Reproduce (for bugs)

  1. Upload object with negative content-length
  2. Restart service to clean up cache
  3. Head object and check size

To avoid service restart, list object versions and check size

Also this unit test should pass

func TestPutObjectWithNegativeContentLength(t *testing.T) {
	tc := prepareHandlerContext(t)

	bktName, objName := "bucket-for-put", "object-for-put"
	createTestBucket(tc, bktName)

	content := []byte("content")
	w, r := prepareTestPayloadRequest(tc, bktName, objName, bytes.NewReader(content))
	r.ContentLength = -1
	tc.Handler().PutObjectHandler(w, r)
	assertStatus(t, w, http.StatusOK)

	w, r = prepareTestRequest(tc, bktName, objName, nil)
	tc.Handler().HeadObjectHandler(w, r)
	assertStatus(t, w, http.StatusOK)
	require.Equal(t, strconv.Itoa(len(content)), w.Header().Get(api.ContentLength))

	// while HEAD request uses cached objectInfo value, listing uses direct tree access
	result := listVersions(t, tc, bktName)
	require.Len(t, result.Version, 1)
	require.EqualValues(t, len(content), result.Version[0].Size)
}

Context

The issue was found during investigation of aws-chunked content-length set up.

Regression

Yes, regression was introduced in 4ad84b9b94 (diff-f8525245fe53f1afda1cefca811b6f70094a431b)

Your Environment

FrostFS S3 Gateway v0.30.2

## Expected Behavior Negative or omitted content-length does not affect size attribute of the object, it sets according to the size of processed payload (#125) ## Current Behavior Cached value contains correct size, but tree node does not. ## Possible Solution Use `createdObject.Size` instead of `p.Size` [here](https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/src/commit/d919e6cce2ed5777c9e9cdc6e0ead6d69862cbbf/api/layer/object.go#L313). It might affect SSE, need to investigate more. ## Steps to Reproduce (for bugs) 1. Upload object with negative content-length 2. Restart service to clean up cache 3. Head object and check size To avoid service restart, list object versions and check size Also this unit test should pass ```go func TestPutObjectWithNegativeContentLength(t *testing.T) { tc := prepareHandlerContext(t) bktName, objName := "bucket-for-put", "object-for-put" createTestBucket(tc, bktName) content := []byte("content") w, r := prepareTestPayloadRequest(tc, bktName, objName, bytes.NewReader(content)) r.ContentLength = -1 tc.Handler().PutObjectHandler(w, r) assertStatus(t, w, http.StatusOK) w, r = prepareTestRequest(tc, bktName, objName, nil) tc.Handler().HeadObjectHandler(w, r) assertStatus(t, w, http.StatusOK) require.Equal(t, strconv.Itoa(len(content)), w.Header().Get(api.ContentLength)) // while HEAD request uses cached objectInfo value, listing uses direct tree access result := listVersions(t, tc, bktName) require.Len(t, result.Version, 1) require.EqualValues(t, len(content), result.Version[0].Size) } ``` ## Context The issue was found during investigation of aws-chunked content-length set up. ## Regression Yes, regression was introduced in https://git.frostfs.info/TrueCloudLab/frostfs-s3-gw/commit/4ad84b9b94ee9bb3b8ed69245c91704deee4835e#diff-f8525245fe53f1afda1cefca811b6f70094a431b ## Your Environment FrostFS S3 Gateway v0.30.2
alexvanin added this to the v0.31.0 milestone 2024-09-10 11:14:45 +00:00
alexvanin added the
bug
label 2024-09-10 11:14:45 +00:00
alexvanin self-assigned this 2024-09-10 11:14:45 +00:00
alexvanin removed their assignment 2024-09-10 11:21:53 +00:00
mbiryukova was assigned by alexvanin 2024-09-10 11:21:53 +00:00
alexvanin modified the milestone from v0.31.0 to v0.30.5 2024-09-16 09:34:51 +00:00
alexvanin modified the milestone from v0.30.5 to v0.30.6 2024-09-16 10:27:30 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-s3-gw#486
No description provided.