Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove exception to status legacy code from http codec #15773

Merged
merged 5 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions source/common/http/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,6 @@
namespace Envoy {
namespace Http {

/**
* Indicates a non-recoverable protocol error that should result in connection termination.
*/
class CodecProtocolException : public EnvoyException {
public:
CodecProtocolException(const std::string& message) : EnvoyException(message) {}
};

/**
* Raised when outbound frame queue flood is detected.
*/
class FrameFloodException : public CodecProtocolException {
public:
FrameFloodException(const std::string& message) : CodecProtocolException(message) {}
};

/**
* Raised when a response is received on a connection that did not send a request. In practice
* this can only happen on HTTP/1.1 connections.
*/
class PrematureResponseException : public EnvoyException {
public:
PrematureResponseException(Http::Code response_code)
: EnvoyException(""), response_code_(response_code) {}

Http::Code responseCode() { return response_code_; }

private:
const Http::Code response_code_;
};

/**
* Indicates a client (local) side error which should not happen.
*/
Expand Down
10 changes: 1 addition & 9 deletions source/common/http/http1/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,6 @@ bool ConnectionImpl::maybeDirectDispatch(Buffer::Instance& data) {
return true;
}

Http::Status ConnectionImpl::dispatch(Buffer::Instance& data) {
// TODO(#10878): Remove this wrapper when exception removal is complete. innerDispatch may either
// throw an exception or return an error status. The utility wrapper catches exceptions and
// converts them to error statuses.
return Utility::exceptionToStatus(
[&](Buffer::Instance& data) -> Http::Status { return innerDispatch(data); }, data);
}

Http::Status ClientConnectionImpl::dispatch(Buffer::Instance& data) {
Http::Status status = ConnectionImpl::dispatch(data);
if (status.ok() && data.length() > 0) {
Expand All @@ -556,7 +548,7 @@ Http::Status ClientConnectionImpl::dispatch(Buffer::Instance& data) {
return status;
}

Http::Status ConnectionImpl::innerDispatch(Buffer::Instance& data) {
Http::Status ConnectionImpl::dispatch(Buffer::Instance& data) {
// Add self to the Dispatcher's tracked object stack.
ScopeTrackerScopeState scope(this, connection_.dispatcher());
ENVOY_CONN_LOG(trace, "parsing {} bytes", connection_, data.length());
Expand Down
9 changes: 0 additions & 9 deletions source/common/http/http1/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,6 @@ class ConnectionImpl : public virtual Connection,
return false;
}

/**
* An inner dispatch call that executes the dispatching logic. While exception removal is in
* migration (#10878), this function may either throw an exception or return an error status.
* Exceptions are caught and translated to their corresponding statuses in the outer level
* dispatch.
* TODO(#10878): Remove this when exception removal is complete.
*/
Http::Status innerDispatch(Buffer::Instance& data);

/**
* Dispatch a memory span.
* @param slice supplies the start address.
Expand Down
18 changes: 1 addition & 17 deletions source/common/http/http2/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,6 @@ void ConnectionImpl::onKeepaliveResponseTimeout() {
}

Http::Status ConnectionImpl::dispatch(Buffer::Instance& data) {
// TODO(#10878): Remove this wrapper when exception removal is complete. innerDispatch may either
// throw an exception or return an error status. The utility wrapper catches exceptions and
// converts them to error statuses.
return Http::Utility::exceptionToStatus(
[&](Buffer::Instance& data) -> Http::Status { return innerDispatch(data); }, data);
}

Http::Status ConnectionImpl::innerDispatch(Buffer::Instance& data) {
ScopeTrackerScopeState scope(this, connection_.dispatcher());
ENVOY_CONN_LOG(trace, "dispatching {} bytes", connection_, data.length());
// Make sure that dispatching_ is set to false after dispatching, even when
Expand Down Expand Up @@ -1710,17 +1702,9 @@ ServerConnectionImpl::trackOutboundFrames(bool is_outbound_flood_monitored_contr
}

Http::Status ServerConnectionImpl::dispatch(Buffer::Instance& data) {
// TODO(#10878): Remove this wrapper when exception removal is complete. innerDispatch may either
// throw an exception or return an error status. The utility wrapper catches exceptions and
// converts them to error statuses.
return Http::Utility::exceptionToStatus(
[&](Buffer::Instance& data) -> Http::Status { return innerDispatch(data); }, data);
}

Http::Status ServerConnectionImpl::innerDispatch(Buffer::Instance& data) {
// Make sure downstream outbound queue was not flooded by the upstream frames.
RETURN_IF_ERROR(protocol_constraints_.checkOutboundFrameLimits());
return ConnectionImpl::innerDispatch(data);
return ConnectionImpl::dispatch(data);
}

absl::optional<int>
Expand Down
11 changes: 0 additions & 11 deletions source/common/http/http2/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,6 @@ class ConnectionImpl : public virtual Connection,
}
}

/**
* An inner dispatch call that executes the dispatching logic. While exception removal is in
* migration (#10878), this function may either throw an exception or return an error status.
* Exceptions are caught and translated to their corresponding statuses in the outer level
* dispatch.
* This needs to be virtual so that ServerConnectionImpl can override.
* TODO(#10878): Remove this when exception removal is complete.
*/
virtual Http::Status innerDispatch(Buffer::Instance& data);

// ScopeTrackedObject
void dumpState(std::ostream& os, int indent_level) const override;

Expand Down Expand Up @@ -654,7 +644,6 @@ class ServerConnectionImpl : public ServerConnection, public ConnectionImpl {
// ServerConnectionImpl objects is called only when processing data from the downstream client in
// the ConnectionManagerImpl::onData method.
Http::Status dispatch(Buffer::Instance& data) override;
Http::Status innerDispatch(Buffer::Instance& data) override;

ServerConnectionCallbacks& callbacks_;

Expand Down
25 changes: 0 additions & 25 deletions source/common/http/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,6 @@
#include "nghttp2/nghttp2.h"

namespace Envoy {
namespace Http {
namespace Utility {
Http::Status exceptionToStatus(std::function<Http::Status(Buffer::Instance&)> dispatch,
Buffer::Instance& data) {
Http::Status status;
TRY_NEEDS_AUDIT {
status = dispatch(data);
// TODO(#10878): Remove this when exception removal is complete. It is currently in migration,
// so dispatch may either return an error status or throw an exception. Soon we won't need to
// catch these exceptions, as all codec errors will be migrated to using error statuses that are
// returned from dispatch.
}
catch (FrameFloodException& e) {
status = bufferFloodError(e.what());
}
catch (CodecProtocolException& e) {
status = codecProtocolError(e.what());
}
catch (PrematureResponseException& e) {
status = prematureResponseError(e.what(), e.responseCode());
}
return status;
}
} // namespace Utility
} // namespace Http
namespace Http2 {
namespace Utility {

Expand Down
6 changes: 0 additions & 6 deletions source/common/http/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ namespace Envoy {
namespace Http {
namespace Utility {

// This is a wrapper around dispatch calls that may throw an exception or may return an error status
// while exception removal is in migration.
// TODO(#10878): Remove this.
Http::Status exceptionToStatus(std::function<Http::Status(Buffer::Instance&)> dispatch,
Buffer::Instance& data);

/**
* Well-known HTTP ALPN values.
*/
Expand Down