Skip to content

Commit df9bce5

Browse files
authored
Merge pull request #1 from PiotrSikora/local-reply-stop2-fixup
review: StopIteration across Contexts.
2 parents 8e22181 + fa1c9c4 commit df9bce5

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
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
@@ -391,7 +386,6 @@ class ContextBase : public RootInterface,
391386
std::shared_ptr<PluginBase> plugin_;
392387
bool in_vm_context_created_ = false;
393388
bool destroyed_ = false;
394-
bool stop_iteration_ = false;
395389

396390
private:
397391
// 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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ SharedData global_shared_data;
226226
} // namespace
227227

228228
DeferAfterCallActions::~DeferAfterCallActions() {
229-
context_->stop_iteration_ = false;
229+
context_->wasm()->stopNextIteration(false);
230230
context_->wasm()->doAfterVmCallActions();
231231
}
232232

@@ -625,22 +625,24 @@ WasmResult ContextBase::setTimerPeriod(std::chrono::milliseconds period,
625625
}
626626

627627
FilterHeadersStatus ContextBase::convertVmCallResultToFilterHeadersStatus(uint64_t result) {
628-
if (stop_iteration_ ||
628+
if (wasm()->isNextIterationStopped() ||
629629
result > static_cast<uint64_t>(FilterHeadersStatus::StopAllIterationAndWatermark)) {
630630
return FilterHeadersStatus::StopAllIterationAndWatermark;
631631
}
632632
return static_cast<FilterHeadersStatus>(result);
633633
}
634634

635635
FilterDataStatus ContextBase::convertVmCallResultToFilterDataStatus(uint64_t result) {
636-
if (stop_iteration_ || result > static_cast<uint64_t>(FilterDataStatus::StopIterationNoBuffer)) {
636+
if (wasm()->isNextIterationStopped() ||
637+
result > static_cast<uint64_t>(FilterDataStatus::StopIterationNoBuffer)) {
637638
return FilterDataStatus::StopIterationNoBuffer;
638639
}
639640
return static_cast<FilterDataStatus>(result);
640641
}
641642

642643
FilterTrailersStatus ContextBase::convertVmCallResultToFilterTrailersStatus(uint64_t result) {
643-
if (stop_iteration_ || result > static_cast<uint64_t>(FilterTrailersStatus::StopIteration)) {
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)