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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = ["crates/server", "crates/agent"]
exclude = ["crates/setup"]

[workspace.package]
version = "3.3.0"
version = "3.4.0"
edition = "2024"
license-file = "LICENSE"
publish = false
Expand Down
8 changes: 5 additions & 3 deletions crates/server/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ impl Drop for Slot<'_> {

/// Outbound payload fetches in flight at once. Each one waits on a blocking thread, so the cap is
/// what keeps a client pointing many jobs at a tarpit URL from taking every thread the server has
/// (main sizes the pool at twice this). ponytail: one global cap, not per org — a single tenant
/// can still use all of it, it just cannot stall /health, logins or agent claims any more.
/// (main sizes the pool at twice this). ponytail: this is the global cap; where it matters (open
/// signup) the per-org cap `MAX_FETCHES_PER_ORG` sits under it so one tenant cannot use all 256.
/// Without that cap a single tenant can still use all of it, it just cannot stall /health, logins
/// or agent claims any more.
pub const OUTBOUND_IN_FLIGHT: usize = 256;

/// Where outbound requests (payload URLs, job callbacks, org event URLs) may connect.
Expand Down Expand Up @@ -341,7 +343,7 @@ pub fn is_http(url: &str) -> bool {
}

// A non-string truthy url gets the scheme error with its repr (Python crashed in urlparse).
fn checked_http_url(url: Option<&Value>) -> Result<&str, DispatchError> {
pub fn checked_http_url(url: Option<&Value>) -> Result<&str, DispatchError> {
match url {
Some(v) if truthy(v) => match v {
Value::String(s) if is_http(s) => Ok(s),
Expand Down
16 changes: 15 additions & 1 deletion crates/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//! (default 3460), PRINTAPI_SIGNUP, PUBLIC_URL, PRINTAPI_PLANS (JSON array or a path to a file
//! holding one), PRINTAPI_BILLING_SECRET, PRINTAPI_TRUSTED_PROXIES (IPs or CIDRs whose
//! `X-Forwarded-For` is believed), PRINTAPI_SIGNUP_QUOTA (monthly job quota of every self-signup
//! org), PRINTAPI_JOB_RETENTION_DAYS (days until finished jobs lose payload, title and
//! org), PRINTAPI_FETCHES_PER_ORG (payload downloads one org may run at once, 0 = no cap; unset:
//! 4 with open signup, else no cap), PRINTAPI_JOB_RETENTION_DAYS (days until finished jobs lose payload, title and
//! callback, and until queued jobs without a deadline are failed; their row goes after
//! max(N, 7) days if it is from before this UTC month; unset or 0 keeps everything), PRINTAPI_TERMS_VERSION (set: `POST /signup`
//! must accept that version of the terms), PRINTAPI_TERMS_URL (required with it), PRINTAPI_DPA_URL,
Expand Down Expand Up @@ -38,6 +39,17 @@ fn parse_quota(raw: &str) -> Result<Option<i64>, String> {
}
}

/// Empty: unset (the default follows the signup mode). Otherwise a non-negative integer, 0 = no cap.
fn parse_fetch_cap(raw: &str) -> Result<Option<usize>, String> {
let t = py_strip(raw);
if t.is_empty() {
return Ok(None);
}
t.parse::<usize>()
.map(Some)
.map_err(|_| format!("must be a non-negative integer, not {t:?}"))
}

/// Empty or 0: keep for ever. Otherwise a positive number of days.
fn parse_retention(raw: &str) -> Result<Option<i64>, String> {
let t = py_strip(raw);
Expand Down Expand Up @@ -174,6 +186,8 @@ fn config() -> Result<(Config, String, u16), String> {
));
}
};
cfg.fetches_per_org = parse_fetch_cap(&env("PRINTAPI_FETCHES_PER_ORG").unwrap_or_default())
.map_err(|e| format!("PRINTAPI_FETCHES_PER_ORG: {e}"))?;
cfg.trusted_proxies = printpapi_server::proxy::TrustedProxies::parse(
&env("PRINTAPI_TRUSTED_PROXIES").unwrap_or_default(),
)
Expand Down
Loading
Loading