OnHttpResponseBody will buffer the whole body when ActionPause returned before
xr opened this issue · 5 comments
Hi,
For this example:
proxy-wasm-go-sdk/examples/http_body/main.go
Line 163 in 1b9daaf
it returns types.ActionPause
when the endOfStream is false, however when endOfStream becomes true and invoke the OnHttpResponseBody again, the bodySize will be the total buffered size instead of the chunk size so that:
ctx.totalResponseBodySize += bodySize
will be doubled accumulated.
some similar discussion on the abi here: https://github.com/proxy-wasm/spec/pull/42/files#r1254823592
checking from envoy code, when using actionPause
from the sdk which is 1
will end up with Http::FilterDataStatus::StopIterationAndBuffer
Then it will buffer the response body: https://github.com/envoyproxy/envoy/blob/77f76d8e9f3d07d45ca70f79929f963f64ae72bb/source/extensions/common/wasm/context.cc#L1775
Wondering does the example need to update if it is the expected behaviour?
@jcchavezs
Yep, check my links in the description, ActionPause
will convert to Http::FilterDataStatus::StopIterationAndBuffer
in envoy which will lead to buffer the responseBody, i think ABI needs to make this part more explicit.
however when endOfStream becomes true and invoke the OnHttpResponseBody again, the bodySize will be the total buffered size instead of the chunk size so that:
The bodySize
in this callback always represented the total available body size, which could be retrieved using GetHttpRequestBody(..., bodySize)
, and not the size of the latest chunk.
@PiotrSikora so you mean to get the size of the body we shouldn't be summing up bodySize but use the latest value instead?
@PiotrSikora so you mean to get the size of the body we shouldn't be summing up bodySize but use the latest value instead?
Correct. Note that summing-up shouldn't be an issue (unless you overflow 32-bits), since GetHttpRequestBody(..., MAX)
will return only as much data as host has available, not more, but it's unnecessary overhead and error-prone coding.