Skip to content

Commit ebd1370

Browse files
committed
Prevent merge queue race condition with global lock
Serialize merge queue processing with global mutex to prevent simultaneous auto builds
1 parent 53899e7 commit ebd1370

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/bors/merge_queue.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::anyhow;
22
use octocrab::models::StatusState;
3-
4-
use std::sync::Arc;
3+
use std::sync::{Arc, OnceLock};
4+
use tokio::sync::Mutex;
55

66
use crate::{
77
BorsContext,
@@ -26,6 +26,8 @@ pub(super) const AUTO_MERGE_BRANCH_NAME: &str = "automation/bors/auto-merge";
2626
/// This branch should run CI checks.
2727
pub(super) const AUTO_BRANCH_NAME: &str = "automation/bors/auto";
2828

29+
static MERGE_QUEUE_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
30+
2931
pub type MergeQueueEvent = ();
3032

3133
enum MergeResult {
@@ -34,6 +36,10 @@ enum MergeResult {
3436
}
3537

3638
pub async fn handle_merge_queue(ctx: Arc<BorsContext>) -> anyhow::Result<()> {
39+
// Prevent concurrent merge queue processing.
40+
let lock = MERGE_QUEUE_LOCK.get_or_init(|| Mutex::new(()));
41+
let _guard = lock.lock().await;
42+
3743
let repos: Vec<Arc<RepositoryState>> =
3844
ctx.repositories.read().unwrap().values().cloned().collect();
3945

0 commit comments

Comments
 (0)