Skip to content
This repository was archived by the owner on Dec 16, 2020. It is now read-only.

Fix wasm onLog#621

Merged
jplevyak merged 2 commits intoenvoyproxy:masterfrom
gargnupur:nup_fix_log
Aug 17, 2020
Merged

Fix wasm onLog#621
jplevyak merged 2 commits intoenvoyproxy:masterfrom
gargnupur:nup_fix_log

Conversation

@gargnupur
Copy link
Copy Markdown
Contributor

Signed-off-by: gargnupur gargnupur@google.com

For an explanation of how to fill out the fields, please see the relevant section
in PULL_REQUESTS.md

Commit Message: Don't return in log, if request is not started. We miss cases like localReply in that scenario
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Deprecated:]

Signed-off-by: gargnupur <gargnupur@google.com>
const StreamInfo::StreamInfo& stream_info) {
if (!http_request_started_) {
return;
onCreate();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to have something like
EnsureContext function, it is very confusing to read that log calls on create.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @jplevyak

This is because http request is not started...
How about something like this in a "EnsureContext" function?
if (asContext()==nullptr) {
onCreate();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a problem with the Envoy interface, so we should not be hacking a patch into the proxy-wasm-cpp-host library. The contract is that onCreate should be called before any other functions are called which require a VM context are called. That was an explicit and intentional design decision. It is up to the Envoy interface code to ensure that all calls into the VM which require a context are bracked with onCreate and onDestroy. It is confusing to see that log() calls onCreate, but that is because Envoy does not have a well defined lifetime for the combined HTTP + AccessLog filter. The solution is the work around this limitation by either 1) not calling into the VM if the Context is not already created (this is the solution which we took earlier and which we now have discovered doesn't work for your use case), or 2) create the VM Context on demand when it is needed for the log() case (as is being done here).

This was discussed with Harvey and it was the decision that Wasm should attempt to fixup the lifetime issues for Envoy Filters to the extent possible. It might be better if we could have a full lifecycle, but sendLocalReply short-circuits that so instead we have a log() call coming without the onRequestHeaders() call which would normally preface it so we can add the onCreate() call here as needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a long winded comment about why we are doing this, including an explicit mention of sendLocalReply and the way that it short circuits the lifecycle of the filter.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jplevyak i understand, in that case it is just naming issue.

If (!context_created) {
OnCreate();
}
?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_vm_context_created_ is already available in the ContextBase superclass object. You could use that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done... ptal

I changed http_request_started to in_vm_context_created_. @jplevyak : I don't think there are there any cases where http_request_started is false and we don't want to call onLog?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. Just a couple of questions to make sure it's working as-intended:

  • is onDestroy still called in the exceptional case?
  • do we need to worry about server-first protocols (onResponse called before onRequest)?

@gargnupur
Copy link
Copy Markdown
Contributor Author

/retest

@mandarjog
Copy link
Copy Markdown
Contributor

@gargnupur @jplevyak is asan failure real?

Signed-off-by: gargnupur <gargnupur@google.com>
@gargnupur
Copy link
Copy Markdown
Contributor Author

@gargnupur @jplevyak is asan failure real?

@mandarjog : looks like not...

@jplevyak
Copy link
Copy Markdown
Contributor

Seems like a timeout @mandarjog

@jplevyak jplevyak merged commit f7ca608 into envoyproxy:master Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants