Fix route limit bound (nginx allows below 65536); the dead-acceptor test kills the presence thread through the clock

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-23 04:15:50 +02:00
commit c38bb36560
3 changed files with 19 additions and 12 deletions

View file

@ -699,12 +699,12 @@ pub struct MemberListenerBinding {
/// route's presence block shares, so this limit is what keeps members from
/// exhausting it.
#[serde(default = "default_member_max_connections")]
pub max_connections: u32,
pub max_connections: u16,
}
const DEFAULT_MEMBER_MAX_CONNECTIONS: u32 = 128;
const DEFAULT_MEMBER_MAX_CONNECTIONS: u16 = 128;
fn default_member_max_connections() -> u32 {
fn default_member_max_connections() -> u16 {
DEFAULT_MEMBER_MAX_CONNECTIONS
}
@ -2446,6 +2446,8 @@ max_connections = {value}"),
);
assert_eq!(limit("7").unwrap().route.unwrap().member.unwrap().max_connections, 7);
assert!(limit("0").is_err());
assert!(limit("65535").is_ok());
assert!(limit("65536").is_err());
// Zero, and a width that overflows u16.
assert!(start("0").is_err());
assert!(start("65530").is_err());

View file

@ -12508,7 +12508,7 @@ processes 9
/// 4103, 4104, 4120 and 4121, so it runs on demand in a container:
/// `cargo test --lib real_nginx -- --ignored`.
#[cfg(unix)]
fn challenges_answered_during_a_member_flood(max_connections: u32) -> Result<usize> {
fn challenges_answered_during_a_member_flood(max_connections: u16) -> Result<usize> {
use std::net::{TcpListener, TcpStream};
use std::process::{Child, Command};
use std::sync::Arc;
@ -12636,9 +12636,9 @@ processes 9
#[test]
#[ignore = "needs nginx on PATH and fixed loopback ports; run in a container"]
fn real_nginx_flood_starves_presence_without_a_member_limit() -> Result<()> {
// The control: the same flood against a limit too high to bind starves
// The control: the same flood against a limit too high to bind (nginx allows up to 65535) starves
// presence, so the test above measures the limit and not the load.
assert!(challenges_answered_during_a_member_flood(100_000)? < 20);
assert!(challenges_answered_during_a_member_flood(60_000)? < 20);
Ok(())
}

View file

@ -28,7 +28,7 @@ use std::thread;
use std::time::{Duration, Instant};
use anyhow::{Context, Result, anyhow, bail, ensure};
use cultcache_rs::{DatabaseEntry, SingleFileMessagePackBackingStore};
use cultcacheclock: Arc::new(PresenceTripwire(FastClock(AtomicU64::new(1_000_000)))),health: Box::new(|_| Arc::new(Health(AtomicBool::new(true)))),rs::{DatabaseEntry, SingleFileMessagePackBackingStore};
use cultnet_rs::{
CultNetMessage, CultNetRawDocumentRecord, CultNetRawPayloadEncoding,
CultNetRudpReliableSendStatus, CultNetRudpSocketTransportConnection,
@ -2592,14 +2592,19 @@ mod tests {
serving.join().unwrap();
}
/// Healthy for everyone but the presence thread, which it kills: the
/// A clock that kills the presence thread when it reads the time: the
/// stand-in for a presence acceptor that dies while the child is fine.
struct PresenceTripwire;
/// Answering a challenge signs, and signing reads the clock.
struct PresenceTripwire(FastClock);
impl HealthProbe for PresenceTripwire {
fn healthy(&self) -> bool {
impl Clock for PresenceTripwire {
fn now_millis(&self) -> u64 {
assert_ne!(thread::current().name(), Some("presence-acceptor"), "presence thread killed");
true
self.0.now_millis()
}
fn sleep(&self, duration: Duration) {
self.0.sleep(duration);
}
}