fix(supabase): R5.5 gate round 1, final errors, four attempts, keys off argv, runbook

This commit is contained in:
bchanot committed 2026-10-23 21:34:24 +02:00
1 parent a481af52c7
commit 56593af25c
10 files changed
+330 -17

No files matched your search

@@ -107,8 +107,17 @@ fn required_env(name: &str) -> Result<String, UploadError> {
.ok_or_else(|| refuse(UploadKind::Destination, format!("{name} is required")))
}
/// The DEV address counts only if it is one of this machine's own addresses (a socket can be
/// bound to it); otherwise it is ignored and only loopback stays allowed.
fn own_address(host: &str) -> bool {
host.parse::<std::net::IpAddr>()
.is_ok_and(|ip| std::net::UdpSocket::bind((ip, 0)).is_ok())
}
fn connect() -> Result<Storage, UploadError> {
let dev_host = env::var("FAUNOSTEO_DEV_HOST").ok();
let dev_host = env::var("FAUNOSTEO_DEV_HOST")
.ok()
.filter(|h| own_address(h));
let destination = check_destination(&required_env("SUPABASE_URL")?, dev_host.as_deref())?;
let key = Secret::new(required_env("SUPABASE_SERVICE_ROLE_KEY")?);
Ok(Storage::new(&destination, key))
@@ -13,7 +13,8 @@ use serde_json::{Value, json};
use ureq::Agent;
const MAX_BODY: u64 = 1024 * 1024;
const ATTEMPTS: u32 = 3;
/// One try and three retries.
const ATTEMPTS: u32 = 4;
/// A key that never prints: `Debug` hides it and there is no `Display`.
pub struct Secret(String);
@@ -61,8 +62,8 @@ impl Storage {
}
}
/// One exchange, retried on a transport error or a 5xx only (a refusal is final). The
/// request is built again on each attempt.
/// One exchange, retried on a transport error or a 5xx only (a refusal, an oversized body
/// and a malformed request are final). The request is built again on each attempt.
fn exchange(
&self,
limit: u64,
@@ -77,7 +78,10 @@ impl Storage {
{
Ok(reply) if reply.status < 500 => return Ok(reply),
Ok(reply) => last = refuse(UploadKind::Network, format!("HTTP {}", reply.status)),
Err(error) => last = refuse(UploadKind::Network, error.to_string()),
Err(error) if is_transient(&error) => {
last = refuse(UploadKind::Network, error.to_string());
}
Err(error) => return Err(final_error(&error)),
}
}
Err(last)
@@ -181,6 +185,34 @@ impl Storage {
}
}
/// The connection could not be made or broke: worth another attempt.
fn is_transient(error: &ureq::Error) -> bool {
matches!(
error,
ureq::Error::Io(_)
| ureq::Error::Timeout(_)
| ureq::Error::HostNotFound
| ureq::Error::ConnectionFailed
| ureq::Error::Protocol(_)
)
}
/// Not retried: a body over its cap is a destination holding something it should not (an
/// object larger than any drawing), anything else a request the tool cannot build (a key with
/// characters a header refuses). The key itself is never part of the message.
fn final_error(error: &ureq::Error) -> UploadError {
match error {
ureq::Error::BodyExceedsLimit(limit) => refuse(
UploadKind::State,
format!("the destination answered more than {limit} bytes"),
),
_ => refuse(
UploadKind::Handshake,
"the request could not be built (check the key)",
),
}
}
fn row_state_of(row: &Value, expected_sha256: &str) -> RowState {
let found = row
.get("sha256")