Skip to content

Commit d10bd28

Browse files
committed
fix(orchestration): report the server's refusal of a snapshot too large to resend plain
A snapshot whose plain JSON exceeds the wire bound can never be accepted uncompressed, so a 400 for the gzip body is returned as is instead of being masked by a second upload that ends in 413.
1 parent b5f41d4 commit d10bd28

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎crates/sqlbuild-orchestration/src/snapshots/main/publish_remote_snapshot.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
use reqwest::StatusCode;
44
use reqwest::header::{CONTENT_ENCODING, CONTENT_TYPE};
55

6-
use crate::api::constants::{GZIP_ENCODING, JSON_MEDIA_TYPE};
6+
use crate::api::constants::{BODY_BYTES, GZIP_ENCODING, JSON_MEDIA_TYPE};
77
use crate::api::errors::ClientError;
88
use crate::api::main::client_response::client_response;
99
use crate::api::main::connect_client::connect_client;
1010
use crate::snapshots::models::{SnapshotInput, SnapshotRecord};
1111
use crate::store::main::compress::compress;
1212

13-
/// Sends the snapshot gzip-encoded, and once more as plain JSON when a server refuses the encoding.
13+
/// Sends the snapshot gzip-encoded, and once more as plain JSON when a server refuses the encoding and the plain body fits the wire bound.
1414
pub async fn publish_remote_snapshot(
1515
server_url: &str,
1616
bearer: &str,
@@ -38,8 +38,9 @@ pub async fn publish_remote_snapshot(
3838
};
3939
match client_response(request(gzipped).header(CONTENT_ENCODING, GZIP_ENCODING)).await {
4040
Err(ClientError::Rejected(status))
41-
if status == StatusCode::BAD_REQUEST
42-
|| status == StatusCode::UNSUPPORTED_MEDIA_TYPE =>
41+
if (status == StatusCode::BAD_REQUEST
42+
|| status == StatusCode::UNSUPPORTED_MEDIA_TYPE)
43+
&& body.len() <= BODY_BYTES =>
4344
{
4445
client_response(request(body)).await
4546
}

‎crates/sqlbuild-orchestration/tests/api/test_publish_encoding.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use reqwest::StatusCode;
1010
use uuid::Uuid;
1111

1212
use crate::api::constants::BODY_BYTES;
13+
use crate::api::errors::ClientError;
1314
use crate::api::tests::helpers::{
1415
gzip_bomb, gzipped_empty_object, large_snapshot, not_gzip, oversized_json, start_api, stop_api,
1516
};
@@ -123,6 +124,15 @@ fn given_encoded_snapshot_bodies_when_publishing_then_gzip_is_bounded_after_auth
123124
.await
124125
.expect("publish a 10k-node snapshot");
125126
assert_eq!(published.generation, 1);
127+
let invalid = SnapshotInput {
128+
generation: 0,
129+
..input
130+
};
131+
let refused = publish_remote_snapshot(&api.url, &token.bearer, &invalid).await;
132+
assert!(
133+
matches!(refused, Err(ClientError::Rejected(StatusCode::BAD_REQUEST))),
134+
"a snapshot too large to resend plain reports the server's own 400, got {refused:?}"
135+
);
126136
let current: serde_json::Value = client
127137
.get(&path)
128138
.bearer_auth(&token.bearer)

0 commit comments

Comments
 (0)