From 597a8ca5d293744026c5975b71e7c6e8ff047c41 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 16:51:33 +0000 Subject: [PATCH] ensure_bucket: wait until the bucket answers (tests' NoSuchBucket race since #176) The baselines flake's cause, printed by #211's diagnostic on main 40dcc92: HTTP 404 NoSuchBucket. In one test binary, baselines' tests all create the bucket at once on a fresh RustFS; one gets 409 while another's create is in progress, and its upload then finds no bucket. ensure_bucket now polls HEAD bucket until it answers (up to 10 s). --- app/src/storage/blobs.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/storage/blobs.rs b/app/src/storage/blobs.rs index a5c3eb13..115c2d8b 100644 --- a/app/src/storage/blobs.rs +++ b/app/src/storage/blobs.rs @@ -259,11 +259,19 @@ impl BlobStore { let url = self.bucket.create_bucket(&self.credentials).sign(URL_TTL); let response = self.http.put(url).send().await.map_err(|e| error(e.to_string()))?; let status = response.status(); - if status.is_success() || status.as_u16() == 409 { - Ok(()) - } else { - Err(error(format!("creating bucket: HTTP {status}"))) + if !(status.is_success() || status.as_u16() == 409) { + return Err(error(format!("creating bucket: HTTP {status}"))); + } + // A 409 can come while another caller is still creating the bucket (tests in one binary all start by making + // it), and an upload straight after then gets NoSuchBucket: wait until the bucket answers. + for _ in 0..100 { + let url = self.bucket.head_bucket(Some(&self.credentials)).sign(URL_TTL); + if self.http.head(url).send().await.is_ok_and(|r| r.status().is_success()) { + return Ok(()); + } + tokio::time::sleep(Duration::from_millis(100)).await; } + Err(error("the bucket still isn't there 10 s after creating it")) } /// The application's store (`S3_*`): one per application, from the container, so its HTTP connections belong to