Skip to content

Commit b1bcf17

Browse files
author
Olivier Bonnaure
committed
fix: prevent orphan re-adoption from reverting blue-green deploy
- Skip orphan re-adoption during active deploy (is_deploying check) - Retry same slot if current slot has no running process instead of alternating - Fixes revert to blue after successful green deploy
1 parent 74f6d58 commit b1bcf17

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/admin/handlers.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,28 @@ pub async fn get_app(state: &Arc<AdminState>, name: &str) -> Response<BoxBody> {
9090
pub async fn post_app_deploy(state: &Arc<AdminState>, name: &str) -> Response<BoxBody> {
9191
match &state.app_manager {
9292
Some(manager) => {
93-
// Determine target slot based on current slot (alternate)
93+
// Determine target slot: if current slot has no running process
94+
// (e.g. after a failed auto-deploy), retry the same slot instead
95+
// of alternating to the other one.
9496
let target_slot = manager
9597
.get_app(name)
9698
.await
9799
.map_or("blue".to_string(), |app| {
98-
if app.current_slot == "blue" {
99-
"green".to_string()
100+
let current_pid = if app.current_slot == "blue" {
101+
app.blue.pid
100102
} else {
101-
"blue".to_string()
103+
app.green.pid
104+
};
105+
if current_pid.is_some() {
106+
// Current slot is running — alternate for blue-green switch
107+
if app.current_slot == "blue" {
108+
"green".to_string()
109+
} else {
110+
"blue".to_string()
111+
}
112+
} else {
113+
// Nothing running on current slot — retry it
114+
app.current_slot.clone()
102115
}
103116
});
104117

src/app/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,14 @@ impl AppManager {
13781378
continue;
13791379
}
13801380
if let Some(found_pid) = find_pid_by_port(port) {
1381+
if self.deployment_manager.is_deploying(&app_name) {
1382+
tracing::debug!(
1383+
"Skipping orphan re-adoption for {} on port {} — deploy in progress",
1384+
app_name,
1385+
port
1386+
);
1387+
continue;
1388+
}
13811389
tracing::warn!(
13821390
"Re-adopting orphaned process PID {} on port {} for {} slot {}",
13831391
found_pid,

src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,19 @@ fn run_app_command(config_path: &str, app_name: &str, action: &str) -> Result<()
421421
.get_app(app_name)
422422
.await
423423
.map_or("blue".to_string(), |app| {
424-
if app.current_slot == "blue" {
425-
"green".to_string()
424+
let current_pid = if app.current_slot == "blue" {
425+
app.blue.pid
426426
} else {
427-
"blue".to_string()
427+
app.green.pid
428+
};
429+
if current_pid.is_some() {
430+
if app.current_slot == "blue" {
431+
"green".to_string()
432+
} else {
433+
"blue".to_string()
434+
}
435+
} else {
436+
app.current_slot.clone()
428437
}
429438
});
430439
app_manager.deploy(app_name, &target_slot).await?;

0 commit comments

Comments
 (0)