Skip to content

Crash support: Restore crash context on filter's posted callback - #16373

Merged
antoniovicente merged 14 commits into
envoyproxy:mainfrom
KBaichoo:filter-cb-crash-support
May 18, 2021
Merged

antoniovicente merged 14 commits into
envoyproxy:mainfrom
KBaichoo:filter-cb-crash-support

Conversation

@KBaichoo

@KBaichoo KBaichoo commented May 6, 2021 •

Copy link
Copy Markdown
Contributor

Implemented Crash Support when processing request or response due to a filter's callback.

Signed-off-by: Kevin Baichoo [email protected]

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

Commit Message:Implemented Crash Support when processing request or response due to a filter's callback.
Additional Description:
Risk Level: medium
Testing: Unit and E2E tests
Docs Changes: NA
Release Notes: Included
Fixes #16241

Some initial discussion on this PR is here: KBaichoo#36

@KBaichoo
KBaichoo requested a review from htuch as a code owner May 6, 2021 21:04
@KBaichoo

KBaichoo commented May 6, 2021

Copy link
Copy Markdown
Contributor Author

/assign @antoniovicente

KBaichoo added 2 commits May 6, 2021 22:20
Signed-off-by: Kevin Baichoo <[email protected]>
Signed-off-by: Kevin Baichoo <[email protected]>
@antoniovicente

Copy link
Copy Markdown
Contributor

kill_request:crash_integration_test seems to be failing due to use-after-free in the gcc build, please take a look since it may be related to this change.

2021-05-07T16:28:46.5830625Z [  DEATH   ] pure virtual method called
2021-05-07T16:28:46.5831134Z [  DEATH   ] terminate called without an active exception

Comment thread include/envoy/http/filter.h Resolved
Comment thread include/envoy/http/filter.h Outdated
* dispatcher.
*/
virtual void restoreContextOnContinue(
std::vector<std::reference_wrapper<const ScopeTrackedObject>>& tracked_objects) PURE;

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.

We may want to pass a ScopeTrackedObjectStack object as an argument and have the restore process add(const ScopeTrackedObject&) to populate the vector.

Comment thread source/common/common/BUILD Resolved
//
// This is currently used to restore the underlying request context if the
// filter continues processing a request due to a callback that it had posted.
class OpaqueScopeTrackedObject : public ScopeTrackedObject {

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 object seems somewhat close to the ScopeTrackedObjectStack object I mentioned in the comment about restore, with some slight differences:

  • Would be good to have an "add" method that the restore method can use to add ScopeTrackedObject to the list of tracked objects
  • Iterating through dumpState directly seems fine, but we could also keep a list of ScopeTrackerScopeState that we append to on add. We need to control the destruction of elements in the list so the destructor should do something like pop_back on the list until the list is empty.

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 object seems somewhat close to the ScopeTrackedObjectStack object

I think they are confusingly close; perhaps ScopeTrackerScopeState could be expanded to support multiple objects per tracker (with the addition of changes suggested by @antoniovicente)?

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.

Sure I'll go with the ScopeTrackedObjectStack that has an add method and iterates through the tracked objects ScopeTrackedObject rather than ScopeTrackerScopeState objects as the latter are only allocable on the stack.

There's a lot of similar sounding terms, so to sum up:

  • ScopeTrackedObject : general interface for an object that supports crash dumping
  • ScopeTrackedObjectStack: a ScopeTrackedObject that encaps multiple tracked objects
  • ScopeTrackerScopeState: a RAII stack-only object that registers a given ScopeTrackedObject on the dispatcher, and removes it on dtor.

Comment thread source/common/http/filter_manager.cc Outdated
}

// Set ScopeTrackerScopeState if there's no existing crash context.
absl::optional<OpaqueScopeTrackedObject> encapsulated_object;

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.

Why did you decide to use absl::optional here?

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.

The optional is to follow the ScopeTrackerScopeState object.

The ScopeTrackerScopeState does RAII, we install it only if there's no existing context. So to conditionally set it we could either do something similar what std::thread does allowing a default inited version that's doesn't have the underlying resource attached, or use optional. The latter seems simpler as the underlying object has less complexity.

This is less of an issue with the use of ScopeTrackedObjectStack described above.

KBaichoo added 3 commits May 10, 2021 19:08
OpaqueScopeTrackedObject.

Signed-off-by: Kevin Baichoo <[email protected]>
Signed-off-by: Kevin Baichoo <[email protected]>

@KBaichoo KBaichoo left a comment

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.

Thanks for the feedback!

Comment thread source/common/http/filter_manager.cc Outdated
}

// Set ScopeTrackerScopeState if there's no existing crash context.
absl::optional<OpaqueScopeTrackedObject> encapsulated_object;

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.

The optional is to follow the ScopeTrackerScopeState object.

The ScopeTrackerScopeState does RAII, we install it only if there's no existing context. So to conditionally set it we could either do something similar what std::thread does allowing a default inited version that's doesn't have the underlying resource attached, or use optional. The latter seems simpler as the underlying object has less complexity.

This is less of an issue with the use of ScopeTrackedObjectStack described above.

//
// This is currently used to restore the underlying request context if the
// filter continues processing a request due to a callback that it had posted.
class OpaqueScopeTrackedObject : public ScopeTrackedObject {

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.

Sure I'll go with the ScopeTrackedObjectStack that has an add method and iterates through the tracked objects ScopeTrackedObject rather than ScopeTrackerScopeState objects as the latter are only allocable on the stack.

There's a lot of similar sounding terms, so to sum up:

  • ScopeTrackedObject : general interface for an object that supports crash dumping
  • ScopeTrackedObjectStack: a ScopeTrackedObject that encaps multiple tracked objects
  • ScopeTrackerScopeState: a RAII stack-only object that registers a given ScopeTrackedObject on the dispatcher, and removes it on dtor.

Signed-off-by: Kevin Baichoo <[email protected]>
@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

Coverage seems to be a flake.

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

Didn't restart the coverage test in the prior kick.

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

antoniovicente
antoniovicente previously approved these changes May 11, 2021

@antoniovicente antoniovicente left a comment

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 good. Thanks.

@antoniovicente

Copy link
Copy Markdown
Contributor

/assign-from @envoyproxy/senior-maintainers

@repokitteh-read-only

Copy link
Copy Markdown

@envoyproxy/senior-maintainers assignee is @htuch

🐱

Caused by: a #16373 (comment) was created by @antoniovicente.

see: more, trace.

Signed-off-by: Kevin Baichoo <[email protected]>
@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

@KBaichoo

Copy link
Copy Markdown
Contributor Author

Think this is another flake...

@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

Comment thread docs/root/version_history/current.rst Outdated
New Features
------------

* crash support: restore crash context when processing requests or responses due to a filter's callback if the callback doesn't already restore the context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Code looks good, but I would really like both here and in interface and other comments below to be more crisp on what a "filter's callback" is. I think this is one of these things that if you've spent a lot of time looking at the problem it's obvious, but to me, there are many callbacks that exist for filters; filters implement callback functions, they invoke callbacks, etc. I think giving an "e.g. foo" would help.

FWIW I think I have some intuition here based on our conversation the other day, but a random reader would not.

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.

htuch
htuch previously approved these changes May 14, 2021

@htuch htuch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

@htuch

htuch commented May 16, 2021

Copy link
Copy Markdown
Member

@KBaichoo CI finally passed but needs merge for version history.

@KBaichoo

Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #16373 (comment) was created by @KBaichoo.

see: more, trace.

Signed-off-by: Kevin Baichoo <[email protected]>
@KBaichoo

Copy link
Copy Markdown
Contributor Author

@htuch merged and CI is now green again.

@antoniovicente

Copy link
Copy Markdown
Contributor

Individual test cases in crash_integration_test take 34 seconds to run. That doesn't seem right. Can we look into where the time is going and if we have overly long timeouts? Sample log below

/wait

2021-05-17T16:32:17.0675140Z [2021-05-17 16:24:43.388][30959][trace][connection] [source/common/network/connection_impl.cc:410] [C16] raising connection event 2
2021-05-17T16:32:17.0676111Z [2021-05-17 16:24:43.388][30959][debug][client] [source/common/http/codec_client.cc:88] [C16] connected
2021-05-17T16:32:17.0677214Z [2021-05-17 16:24:43.388][19743][trace][misc] [source/common/event/scaled_range_timer_manager_impl.cc:60] enableTimer called on 0x2fb5a00 for 3600000ms, min is 3600000ms
2021-05-17T16:32:17.0678338Z [2021-05-17 16:25:17.074][30959][debug][connection] [source/common/network/connection_impl.cc:133] [C16] closing data_to_write=0 type=1
2021-05-17T16:32:17.0679549Z [2021-05-17 16:25:17.074][30959][debug][connection] [source/common/network/connection_impl.cc:243] [C16] closing socket: 1

@KBaichoo

Copy link
Copy Markdown
Contributor Author

The longer runtime above is when running with coverage.

See: https://dev.azure.com/cncf/4684fb3d-0389-4e0b-8251-221942316e06/_apis/build/builds/75892/logs/262

These tests execute much faster under normal runs ~13s : https://dev.azure.com/cncf/4684fb3d-0389-4e0b-8251-221942316e06/_apis/build/builds/75936/logs/68

The tests don't do anything fancy compared to other integration tests apart from death.

WDYT we should do?

@antoniovicente

Copy link
Copy Markdown
Contributor

13 seconds for normal runs vs 420 seconds under coverage is surprising. It's possible that this is related to death tests and coverage.

I guess we should merge this PR, let me take one final look.

@antoniovicente
antoniovicente merged commit 196f849 into envoyproxy:main May 18, 2021
ntgsx92 pushed a commit to ntgsx92/envoy that referenced this pull request May 18, 2021
…oyproxy#16373)

Implemented Crash Support when processing request or response due to a filter's callback.

Signed-off-by: Kevin Baichoo <[email protected]>
Signed-off-by: Sixiang Gu <[email protected]>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
…oyproxy#16373)

Implemented Crash Support when processing request or response due to a filter's callback.

Signed-off-by: Kevin Baichoo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash support: Restore crash context on filter's posted callback

4 participants