S010: parts refused together lower the host's count

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-25 06:47:01 -06:00
commit 6bf1f3c431
4 changed files with 35 additions and 2 deletions

View file

@ -354,7 +354,13 @@ impl<'a> Run<'a> {
let s = &mut self.slots[i];
let wait = backoff(self.options, s.fails).max(retry_after.unwrap_or_default());
let hopeless = others == 0 && (s.fails >= self.options.tries || retry_after.is_some_and(|d| d > self.options.max_wait));
match weigh(&e) {
let weight = weigh(&e);
if matches!(weight, Weight::Refused { again: true }) && others == 0 && running > 0 {
// Maybe too many at once, though none got anywhere: for now fewer, also if this run ends.
let pause = retry_after.unwrap_or_default().min(self.options.timing.refused);
self.hosts.refused(&self.host, now + pause + self.options.timing.window * 3);
}
match weight {
Weight::Fatal => return self.fail(e),
Weight::Refused { again: false } if others == 0 => return self.fail(e),
_ if hopeless => return self.fail(e),

View file

@ -242,6 +242,31 @@ async fn a_refused_connection_steps_down_and_is_remembered() {
assert!(b.server.requests_for(path)[..4].iter().all(|r| r.status != 429));
}
#[tokio::test(flavor = "multi_thread")]
async fn two_refused_at_once_come_back_as_one() {
let _alone = ALONE.lock().await;
let b = Bench::new(8).await;
let path = "/data/3/4m/t.bin";
// After the probe, with a pause that is too long to sit out.
let refuse = Faults { expire_requests: Some(1), expire_status: Some(429), retry_after: Some(5), ..Faults::default() };
b.server.set_faults(path, refuse);
let id = b.add(path);
assert!(matches!(b.run(id).await, Err(Error::Status { code: 429, .. })));
assert!(b.server.log().len() >= 3, "two parts began");
b.server.clear_all_faults();
tokio::time::sleep(ms(5200)).await;
b.server.set_faults(path, slow(3 * MB));
let start = Instant::now();
let watch = async {
while start.elapsed() < ms(800) {
assert!(b.monitor.snapshot().connections < 2, "one at a time for now");
tokio::time::sleep(ms(5)).await;
}
};
let (done, ()) = tokio::join!(b.run(id), watch);
check(&done.unwrap(), 3, 4 * MB);
}
#[tokio::test(flavor = "multi_thread")]
async fn one_broken_part_does_not_stop_the_others() {
let _alone = ALONE.lock().await;

View file

@ -44,7 +44,8 @@ fn config(dir: &Path, recovery: Recovery) -> Config {
patience: ms(500),
tries: 2,
backoff: ms(20),
max_wait: ms(500),
// Longer than the pause the test server asks for, as outside of tests.
max_wait: ms(1500),
checkpoint: ms(50),
};
let mut config = Config::new(Shared { client, store, hosts }, LIMITS);

View file

@ -115,6 +115,7 @@ Verified: `--test auth` green (21: redirect leaks, store, logs and arguments sea
- A proxy is `system`, `direct`, `http://…`, `https://…` or `socks5://…`. `sites.trust.refused(host)` is the certificate to put in `Site::certificate` when the user says so.
Not done: the exception shows a fingerprint only (no issuer or dates); proxies that ask for anything but a plain login; FTP logins; connections of a host are still first come, first served; nothing deletes a task's keyring item yet, when the task goes for good or gets another `secret` (Edit, `Command::Continue`): whoever first saves task secrets (the connector) must add that, and keep items another task shares (KeepBoth). Never tried against the real keyring, portal, servers or proxies.
Seen: until fixed, a test's `dbus-daemon --session` started real services from the system's list (gnome-keyring's starter found the running one and ended; portal, gvfs). No secret was read or written, nothing was left over. `auth.rs` has a bus without services; `recover.rs` still has the old one, but asks for no such names. Boxes were ticked together at the end, against rule 3.
Fixed after review: `matrix` (max_conns) was flaky, also at 49f6e5d (2 of 10 under load): parts that started together and were all refused didn't count as too many, so every retry began with two again. Now the host stands fewer for a while (Retry-After and three windows), test `two_refused_at_once_come_back_as_one`; the test's `max_wait` is above the server's 1 s pause, as in real use. 12 of 12 under load.
## Later
-