Repository navigation
ext_proc: Fix a potential crash on gRPC failure - #15611
Conversation
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]>
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; |
There was a problem hiding this comment.
Should this happen earlier, i.e. at the start of this basic block, before we try to reopen the stream again with the start?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
LGTM modulo possible bug in openStream.
Signed-off-by: Gregory Brail <[email protected]>
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]