Skip to content

Commit b7d3d13

Browse files
authored
Clear stop_iteration_ in DeferAfterCallActions destructor (#93)
Signed-off-by: mathetake <takeshi@tetrate.io> Signed-off-by: Piotr Sikora <piotrsikora@google.com>
1 parent 376ffaf commit b7d3d13

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

include/proxy-wasm/context.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ class ContextBase : public RootInterface,
167167
// Called before deleting the context.
168168
virtual void destroy();
169169

170-
// Called to raise the flag which indicates that the context should stop iteration regardless of
171-
// returned filter status from Proxy-Wasm extensions. For example, we ignore
172-
// FilterHeadersStatus::Continue after a local reponse is sent by the host.
173-
void stopIteration() { stop_iteration_ = true; };
174-
175170
/**
176171
* Calls into the VM.
177172
* These are implemented by the proxy-independent host code. They are virtual to support some
@@ -390,7 +385,6 @@ class ContextBase : public RootInterface,
390385
std::shared_ptr<PluginBase> plugin_;
391386
bool in_vm_context_created_ = false;
392387
bool destroyed_ = false;
393-
bool stop_iteration_ = false;
394388

395389
private:
396390
// helper functions

include/proxy-wasm/wasm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
122122

123123
AbiVersion abiVersion() { return abi_version_; }
124124

125+
// Called to raise the flag which indicates that the context should stop iteration regardless of
126+
// returned filter status from Proxy-Wasm extensions. For example, we ignore
127+
// FilterHeadersStatus::Continue after a local reponse is sent by the host.
128+
void stopNextIteration(bool stop) { stop_iteration_ = stop; };
129+
bool isNextIterationStopped() { return stop_iteration_; };
130+
125131
void addAfterVmCallAction(std::function<void()> f) { after_vm_call_actions_.push_back(f); }
126132
void doAfterVmCallActions() {
127133
// NB: this may be deleted by a delayed function unless prevented.
@@ -223,6 +229,7 @@ class WasmBase : public std::enable_shared_from_this<WasmBase> {
223229
std::string code_;
224230
std::string vm_configuration_;
225231
bool allow_precompiled_ = false;
232+
bool stop_iteration_ = false;
226233
FailState failed_ = FailState::Ok; // Wasm VM fatal error.
227234

228235
// ABI version.

src/context.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ SharedData global_shared_data;
225225

226226
} // namespace
227227

228-
DeferAfterCallActions::~DeferAfterCallActions() { wasm_->doAfterVmCallActions(); }
228+
DeferAfterCallActions::~DeferAfterCallActions() {
229+
wasm_->stopNextIteration(false);
230+
wasm_->doAfterVmCallActions();
231+
}
229232

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

624627
FilterHeadersStatus ContextBase::convertVmCallResultToFilterHeadersStatus(uint64_t result) {
625-
if (stop_iteration_ ||
628+
if (wasm()->isNextIterationStopped() ||
626629
result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark)) {
627-
stop_iteration_ = false;
628630
return FilterHeadersStatus::StopAllIterationAndWatermark;
629631
}
630632
return static_cast<FilterHeadersStatus>(result);
631633
}
632634

633635
FilterDataStatus ContextBase::convertVmCallResultToFilterDataStatus(uint64_t result) {
634-
if (stop_iteration_ || result > static_cast<uint64_t>(FilterDataStatus::StopIterationNoBuffer)) {
635-
stop_iteration_ = false;
636+
if (wasm()->isNextIterationStopped() ||
637+
result > static_cast<uint64_t>(FilterDataStatus::StopIterationNoBuffer)) {
636638
return FilterDataStatus::StopIterationNoBuffer;
637639
}
638640
return static_cast<FilterDataStatus>(result);
639641
}
640642

641643
FilterTrailersStatus ContextBase::convertVmCallResultToFilterTrailersStatus(uint64_t result) {
642-
if (stop_iteration_ || result > static_cast<uint64_t>(FilterTrailersStatus::StopIteration)) {
643-
stop_iteration_ = false;
644+
if (wasm()->isNextIterationStopped() ||
645+
result > static_cast<uint64_t>(FilterTrailersStatus::StopIteration)) {
644646
return FilterTrailersStatus::StopIteration;
645647
}
646648
return static_cast<FilterTrailersStatus>(result);

src/exports.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Word send_local_response(void *raw_context, Word response_code, Word response_co
186186
auto additional_headers = toPairs(additional_response_header_pairs.value());
187187
context->sendLocalResponse(response_code, body.value(), std::move(additional_headers), grpc_code,
188188
details.value());
189-
context->stopIteration();
189+
context->wasm()->stopNextIteration(true);
190190
return WasmResult::Ok;
191191
}
192192

0 commit comments

Comments
 (0)