Skip to content

ext_proc: Fix a potential crash on gRPC failure - #15611

Merged
htuch merged 3 commits into
envoyproxy:mainfrom
gbrail:ext-proc-bug-1
Mar 25, 2021
Merged

htuch merged 3 commits into
envoyproxy:mainfrom
gbrail:ext-proc-bug-1

Conversation

@gbrail

@gbrail gbrail commented Mar 22, 2021

Copy link
Copy Markdown
Contributor

Commit Message: If the external processing server used by the ext_proc filter is unavailable, it is possible that an error delivered while trying to start the gRPC stream would result in a crash.

Additional Description: This depends on the result of a race condition and is not always reproducable. I already checked with the envoy-security group.

Risk Level: Low: This fixes a possible crash bug.

Testing: Extended existing unit tests, and tested manually as well to verify.

Docs Changes:
Release Notes:
Platform Specific Features:
Signed-off-by: Gregory Brail [email protected]

If the external processing server used by the ext_proc filter is
unavailable, it is possible that an error delivered while trying
to start the gRPC stream would result in a crash. This depends on the
result of a race condition and is not always reproducable.

Signed-off-by: Gregory Brail <[email protected]>
@gbrail
gbrail marked this pull request as ready for review March 23, 2021 00:37
@gbrail
gbrail requested a review from snowp as a code owner March 23, 2021 00:37
Return an enum with the three possible states from an attempt
to open the gRPC stream and use it as necessary.

Signed-off-by: Gregory Brail <[email protected]>
stats_.streams_started_.inc();
if (processing_complete_) {
// Stream failed while starting and either onGrpcError or onGrpcClose was already called
return sent_immediate_response_ ? StreamOpenState::Error : StreamOpenState::IgnoreError;

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.

Should this happen earlier, i.e. at the start of this basic block, before we try to reopen the stream again with the start?

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.

No, all the callback functions check this before calling openStream() and bail out early.

We'll only call openStream() the first time the filter needs to send something on the stream, and since we have a flexible processing mode, any callback could be the first one to need to open the stream. The callback actually never resets stream_ (it's a unique_ptr) so we have a failsafe to ensure it's never opened twice.

The bug that this PR fixes is that the gRPC client might call onGrpcError as part of the "client_->start()" call. So, if processing_complete_ is set now, then it means that this happened, which tells us that the stream failed to open.

I think this is all correct.

One thing I could see doing is asserting that processing_complete_ is false at the start of this method just to ensure that all the other callbacks are calling it appropriately. Either that or come up with some sort of "state" enum for the filter to make all of these lifecycle things more explicit.

@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 modulo possible bug in openStream.

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants