Skip to content
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
7 changes: 4 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1872,12 +1872,12 @@ dependencies = [

[[package]]
name = "http-body-util"
version = "0.1.2"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f"
checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"
dependencies = [
"bytes",
"futures-util",
"futures-core",
"http",
"http-body",
"pin-project-lite",
Expand Down Expand Up @@ -4506,6 +4506,7 @@ dependencies = [
"futures",
"hashbrown 0.15.4",
"http",
"http-body-util",
"hyper",
"hyper-util",
"insta",
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ hex = "0.4.3"
hmac = "0.12.1"
hostname = "0.4.1"
http = "1.3.1"
http-body-util = "0.1.3"
human-size = "0.4.3"
hyper = "1.7.0"
hyper-util = { version = "0.1.17", features = ["tokio"] }
Expand Down
1 change: 1 addition & 0 deletions relay-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ either = { workspace = true }
flate2 = { workspace = true }
futures = { workspace = true, features = ["async-await"] }
hashbrown = { workspace = true }
http-body-util = { workspace = true }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added this only to be able to reference the type. The dependency was already in our tree.

hyper = { workspace = true }
hyper-util = { workspace = true }
itertools = { workspace = true }
Expand Down
16 changes: 16 additions & 0 deletions relay-server/src/utils/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ impl IntoResponse for ForwardError {
HttpError::Misconfigured => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
},
Self::Upstream(UpstreamRequestError::SendFailed(e)) => {
if has_source::<http_body_util::LengthLimitError>(&e) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The length limit error is deeply nested:

Upstream(
        SendFailed(
            reqwest::Error {
                kind: Request,
                url: "http://127.0.0.1:56750/api/42/attachment/?sentry_key=f78f4884d0c44e9ead0c80a42e949b50",
                source: hyper_util::client::legacy::Error(
                    SendRequest,
                    hyper::Error(
                        User(
                            Body,
                        ),
                        reqwest::Error {
                            kind: Body,
                            source: Error {
                                inner: LengthLimitError,
                            },
                        },
                    ),
                ),
            },
        ),
    ),

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.

Is there another option with a different/wrapped middleware which makes this less tedious?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could possibly make this a little more flat, but the basic problem is that since we're now streaming, the error occurs in the reqwest library while sending the outbound request.

return StatusCode::PAYLOAD_TOO_LARGE.into_response();
}
if e.is_timeout() {
StatusCode::GATEWAY_TIMEOUT.into_response()
} else {
Expand All @@ -82,6 +85,7 @@ impl IntoResponse for ForwardError {
}

/// A http response of a successfully forwarded request.
#[derive(Debug)]
pub struct ForwardResponse {
status: StatusCode,
headers: HeaderMap,
Expand Down Expand Up @@ -331,3 +335,15 @@ impl ForwardRequestBuilder {
Ok(tokio::time::timeout(self.timeout, self.receiver).await???)
}
}

/// Returns `true` if any of the error's sources matches the given type.
fn has_source<T: std::error::Error + 'static>(error: &dyn std::error::Error) -> bool {
let mut source = error.source();
while let Some(s) = source {
if s.downcast_ref::<T>().is_some() {
return true;
}
source = s.source();
}
false
}
6 changes: 5 additions & 1 deletion tests/integration/fixtures/mini_sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ def get_error_message(data):
def count_hits():
# Consume POST body even if we don't like this request
# to no clobber the socket and buffers
_ = flask_request.data
try:
_ = flask_request.data
except Exception:
# stream might be invalid
pass
Comment on lines +306 to +308
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without this, the integration test crashes before we see what relay responds with.


if flask_request.url_rule:
sentry.hit(flask_request.url_rule.rule)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_store_allowed_origins_passes(mini_sentry, relay, allowed_origins):
[
"/api/42/store/",
"/api/42/envelope/",
"/api/666/envelope/",
"/api/42/attachment/",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed this back to the original. By using /api/666/envelope/, I obscured the bug that this PR fixes.

"/api/42/minidump/",
],
)
Expand Down
Loading