Skip to content

Commit eb92380

Browse files
committed
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).
1 parent 40dcc92 commit eb92380

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎app/src/storage/blobs.rs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,19 @@ impl BlobStore {
259259
let url = self.bucket.create_bucket(&self.credentials).sign(URL_TTL);
260260
let response = self.http.put(url).send().await.map_err(|e| error(e.to_string()))?;
261261
let status = response.status();
262-
if status.is_success() || status.as_u16() == 409 {
263-
Ok(())
264-
} else {
265-
Err(error(format!("creating bucket: HTTP {status}")))
262+
if !(status.is_success() || status.as_u16() == 409) {
263+
return Err(error(format!("creating bucket: HTTP {status}")));
264+
}
265+
// A 409 can come while another caller is still creating the bucket (tests in one binary all start by making
266+
// it), and an upload straight after then gets NoSuchBucket: wait until the bucket answers.
267+
for _ in 0..100 {
268+
let url = self.bucket.head_bucket(Some(&self.credentials)).sign(URL_TTL);
269+
if self.http.head(url).send().await.is_ok_and(|r| r.status().is_success()) {
270+
return Ok(());
271+
}
272+
tokio::time::sleep(Duration::from_millis(100)).await;
266273
}
274+
Err(error("the bucket still isn't there 10 s after creating it"))
267275
}
268276

269277
/// The application's store (`S3_*`): one per application, from the container, so its HTTP connections belong to

0 commit comments

Comments
 (0)