Don't return 200 code when object body is not found #158

Closed
opened 2023-06-30 07:33:40 +00:00 by dkirillov · 1 comment
Member

As mentioned in #156 we get 200 http code because of writing header before reading object from FrostFS (if object id exists in the cache but not in storage we get 200 code and error in body)

Expected Behavior

Get 404 status if object not found even when cache contains object header

Current Behavior

We get 200 OK but the body right away contains NoSuchKey error

Possible Solution

Probably we can write status code header right after init reading

Steps to Reproduce (for bugs)


func TestGetObject(t *testing.T) {
	hc := prepareHandlerContext(t)
	bktName, objName := "bucket", "obj"
	bktInfo, objInfo := createVersionedBucketAndObject(hc.t, hc, bktName, objName)

	putObject(hc.t, hc, bktName, objName)

	checkFound(hc.t, hc, bktName, objName, objInfo.VersionID())
	checkFound(hc.t, hc, bktName, objName, emptyVersion)

	addr := getAddressOfLastVersion(hc, bktInfo, objName)
	hc.tp.SetObjectError(addr, apistatus.ObjectNotFound{})
	hc.tp.SetObjectError(objInfo.Address(), apistatus.ObjectNotFound{})

	getObjectAssertS3Error(hc, bktName, objName, objInfo.VersionID(), s3errors.ErrNoSuchVersion) // the 'getObjectAssertS3Error' similar to 'headObjectAssertS3Error'
	getObjectAssertS3Error(hc, bktName, objName, emptyVersion, s3errors.ErrNoSuchKey)
}

Your Environment

  • Version used: v0.27.0-rc.1-69-g2cbe3b9a
As mentioned in #156 we get `200` http code because of [writing header before reading object from](https://git.frostfs.info/dkirillov/frostfs-s3-gw/src/commit/1587180b9e2f013aad98d17ebeffb895887dcc03/api/handler/get.go#L204-L209) FrostFS (if object id exists in the cache but not in storage we get 200 code and error in body) ## Expected Behavior Get 404 status if `object not found` even when cache contains object header ## Current Behavior We get 200 OK but the body right away contains `NoSuchKey` error ## Possible Solution Probably we can write status code header right after [init reading](https://git.frostfs.info/dkirillov/frostfs-s3-gw/src/commit/1587180b9e2f013aad98d17ebeffb895887dcc03/api/layer/layer.go#L422-L425) ## Steps to Reproduce (for bugs) <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug. --> ```golang func TestGetObject(t *testing.T) { hc := prepareHandlerContext(t) bktName, objName := "bucket", "obj" bktInfo, objInfo := createVersionedBucketAndObject(hc.t, hc, bktName, objName) putObject(hc.t, hc, bktName, objName) checkFound(hc.t, hc, bktName, objName, objInfo.VersionID()) checkFound(hc.t, hc, bktName, objName, emptyVersion) addr := getAddressOfLastVersion(hc, bktInfo, objName) hc.tp.SetObjectError(addr, apistatus.ObjectNotFound{}) hc.tp.SetObjectError(objInfo.Address(), apistatus.ObjectNotFound{}) getObjectAssertS3Error(hc, bktName, objName, objInfo.VersionID(), s3errors.ErrNoSuchVersion) // the 'getObjectAssertS3Error' similar to 'headObjectAssertS3Error' getObjectAssertS3Error(hc, bktName, objName, emptyVersion, s3errors.ErrNoSuchKey) } ``` ## Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * Version used: v0.27.0-rc.1-69-g2cbe3b9a
dkirillov added the
bug
label 2023-06-30 07:33:40 +00:00
dkirillov self-assigned this 2023-07-06 11:24:10 +00:00
Owner

Done in #164

Done in #164
alexvanin added this to the v0.28.0 milestone 2023-07-20 10:05:40 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#158
No description provided.