Skip to content
Closed
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
21 changes: 17 additions & 4 deletions src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub struct Config {
/// told to start over (262144; 0 keeps none).
pub group_log_bytes: usize,
/// `STREAMGRES_MAX_MESSAGE_BYTES`: the largest inbound WebSocket message
/// accepted (16 MiB).
/// accepted (16 MiB). Must be a positive number of bytes.
pub max_message_bytes: usize,
/// `STREAMGRES_BYTES_PER_PART`: how many bytes of serialized row
/// operations one poke part carries at most (768000, i.e. 750 KiB).
Expand Down Expand Up @@ -373,9 +373,15 @@ impl Config {
None => 256 * 1024,
},
max_message_bytes: match first(&["STREAMGRES_MAX_MESSAGE_BYTES"]) {
Some(text) => text.parse().map_err(|_| {
format!("STREAMGRES_MAX_MESSAGE_BYTES must be a number, got `{text}`")
})?,
Some(text) => text
.parse::<usize>()
.ok()
.filter(|bytes| *bytes > 0)
.ok_or_else(|| {
format!(
"STREAMGRES_MAX_MESSAGE_BYTES must be a positive number of bytes, got `{text}`"
)
})?,
None => 16 * 1024 * 1024,
},
bytes_per_part: match first(&["STREAMGRES_BYTES_PER_PART"]) {
Expand Down Expand Up @@ -630,6 +636,13 @@ mod tests {
);
}

/// Zero disables the message size cap, so it is refused.
#[test]
fn zero_max_message_bytes_is_refused() {
let error = config(&[("STREAMGRES_MAX_MESSAGE_BYTES", "0")]).unwrap_err();
assert!(error.contains("STREAMGRES_MAX_MESSAGE_BYTES"), "{error}");
}

/// A value that is not a number is refused by the variable's name.
#[test]
fn a_malformed_keepalive_is_refused_by_name() {
Expand Down
Loading