Skip to content

Commit

Permalink
Defer sendLocalReply() to prevent reentrant calls. (envoyproxy#597)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored Aug 4, 2020
1 parent ef2850f commit 4689a30
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions source/extensions/common/wasm/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,16 @@ WasmResult Context::sendLocalResponse(uint32_t response_code, absl::string_view
}
};
if (decoder_callbacks_) {
decoder_callbacks_->sendLocalReply(static_cast<Envoy::Http::Code>(response_code), body_text,
modify_headers, grpc_status, details);
// This is a bit subtle because proxy_on_delete() does call DeferAfterCallActions(),
// so in theory it could call this and the Context in the VM would be invalid,
// but because it only gets called after the connections have drained, the call to
// sendLocalReply() will fail. Net net, this is safe.
wasm()->addAfterVmCallAction([this, response_code, body_text = std::string(body_text),
modify_headers = std::move(modify_headers), grpc_status,
details = std::string(details)] {
decoder_callbacks_->sendLocalReply(static_cast<Envoy::Http::Code>(response_code), body_text,
modify_headers, grpc_status, details);
});
}
return WasmResult::Ok;
}
Expand Down

0 comments on commit 4689a30

Please sign in to comment.