Skip to content

Commit 2518d8d

Browse files
authored
fix: add if-not-exists check to prevent concurrency issues when initializing S3 channel (#1915)
1 parent c101ccc commit 2518d8d

File tree

1 file changed

+16
-4
lines changed
  • crates/rattler_index/src

1 file changed

+16
-4
lines changed

crates/rattler_index/src/lib.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,11 +1286,23 @@ pub async fn ensure_channel_initialized(op: &Operator) -> anyhow::Result<()> {
12861286
};
12871287

12881288
let repodata_bytes = serde_json::to_vec(&empty_repodata)?;
1289-
op.write_with(&noarch_repodata_path, repodata_bytes)
1289+
match op
1290+
.write_with(&noarch_repodata_path, repodata_bytes)
1291+
.if_not_exists(true)
12901292
.cache_control(CACHE_CONTROL_REPODATA)
1291-
.await?;
1292-
1293-
Ok(())
1293+
.await
1294+
{
1295+
Ok(_) => {
1296+
tracing::info!("Successfully initialized channel");
1297+
Ok(())
1298+
}
1299+
Err(e) if e.kind() == opendal::ErrorKind::ConditionNotMatch => {
1300+
// Another process created the file - that's fine, channel is initialized
1301+
tracing::debug!("Channel already initialized by another process");
1302+
Ok(())
1303+
}
1304+
Err(e) => Err(e.into()),
1305+
}
12941306
}
12951307

12961308
/// Ensures that a filesystem channel has a valid `noarch/repodata.json` file.

0 commit comments

Comments
 (0)