Skip to content

Commit

Permalink
Clear stop_iteration_ in DeferAfterCallActions destructor (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: mathetake <takeshi@tetrate.io>
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
  • Loading branch information
mathetake authored Nov 10, 2020
1 parent 376ffaf commit b7d3d13
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
6 changes: 0 additions & 6 deletions include/proxy-wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ class ContextBase : public RootInterface,
// Called before deleting the context.
virtual void destroy();

// Called to raise the flag which indicates that the context should stop iteration regardless of
// returned filter status from Proxy-Wasm extensions. For example, we ignore
// FilterHeadersStatus::Continue after a local reponse is sent by the host.
void stopIteration() { stop_iteration_ = true; };

/**
* Calls into the VM.
* These are implemented by the proxy-independent host code. They are virtual to support some
Expand Down Expand Up @@ -390,7 +385,6 @@ class ContextBase : public RootInterface,
std::shared_ptr<PluginBase> plugin_;
bool in_vm_context_created_ = false;
bool destroyed_ = false;
bool stop_iteration_ = false;

private:
// helper functions
Expand Down
7 changes: 7 additions & 0 deletions include/proxy-wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {

AbiVersion abiVersion() { return abi_version_; }

// Called to raise the flag which indicates that the context should stop iteration regardless of
// returned filter status from Proxy-Wasm extensions. For example, we ignore
// FilterHeadersStatus::Continue after a local reponse is sent by the host.
void stopNextIteration(bool stop) { stop_iteration_ = stop; };
bool isNextIterationStopped() { return stop_iteration_; };

void addAfterVmCallAction(std::function<void()> f) { after_vm_call_actions_.push_back(f); }
void doAfterVmCallActions() {
// NB: this may be deleted by a delayed function unless prevented.
Expand Down Expand Up @@ -223,6 +229,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
std::string code_;
std::string vm_configuration_;
bool allow_precompiled_ = false;
bool stop_iteration_ = false;
FailState failed_ = FailState::Ok; // Wasm VM fatal error.

// ABI version.
Expand Down
16 changes: 9 additions & 7 deletions src/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ SharedData global_shared_data;

} // namespace

DeferAfterCallActions::~DeferAfterCallActions() { wasm_->doAfterVmCallActions(); }
DeferAfterCallActions::~DeferAfterCallActions() {
wasm_->stopNextIteration(false);
wasm_->doAfterVmCallActions();
}

WasmResult BufferBase::copyTo(WasmBase *wasm, size_t start, size_t length, uint64_t ptr_ptr,
uint64_t size_ptr) const {
Expand Down Expand Up @@ -622,25 +625,24 @@ WasmResult ContextBase::setTimerPeriod(std::chrono::milliseconds period,
}

FilterHeadersStatus ContextBase::convertVmCallResultToFilterHeadersStatus(uint64_t result) {
if (stop_iteration_ ||
if (wasm()->isNextIterationStopped() ||
result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark)) {
stop_iteration_ = false;
return FilterHeadersStatus::StopAllIterationAndWatermark;
}
return static_cast<FilterHeadersStatus>(result);
}

FilterDataStatus ContextBase::convertVmCallResultToFilterDataStatus(uint64_t result) {
if (stop_iteration_ || result > static_cast<uint64_t>(FilterDataStatus::StopIterationNoBuffer)) {
stop_iteration_ = false;
if (wasm()->isNextIterationStopped() ||
result > static_cast<uint64_t>(FilterDataStatus::StopIterationNoBuffer)) {
return FilterDataStatus::StopIterationNoBuffer;
}
return static_cast<FilterDataStatus>(result);
}

FilterTrailersStatus ContextBase::convertVmCallResultToFilterTrailersStatus(uint64_t result) {
if (stop_iteration_ || result > static_cast<uint64_t>(FilterTrailersStatus::StopIteration)) {
stop_iteration_ = false;
if (wasm()->isNextIterationStopped() ||
result > static_cast<uint64_t>(FilterTrailersStatus::StopIteration)) {
return FilterTrailersStatus::StopIteration;
}
return static_cast<FilterTrailersStatus>(result);
Expand Down
2 changes: 1 addition & 1 deletion src/exports.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Word send_local_response(void *raw_context, Word response_code, Word response_co
auto additional_headers = toPairs(additional_response_header_pairs.value());
context->sendLocalResponse(response_code, body.value(), std::move(additional_headers), grpc_code,
details.value());
context->stopIteration();
context->wasm()->stopNextIteration(true);
return WasmResult::Ok;
}

Expand Down

0 comments on commit b7d3d13

Please sign in to comment.