Skip to content

Commit 244c892

Browse files
pzhan9meta-codesync[bot]
authored andcommitted
dedup code related to tail_str in spawn_exit_monitor (#1922)
Summary: Pull Request resolved: #1922 This block is duplicated in 4 if-else branches: ``` let tail_str = if stderr_tail.is_empty() { None } else { Some(stderr_tail.join("\n")) }; ``` This diff extracts it out and log it in the `tail` field. Reviewed By: thedavekwon Differential Revision: D87344528 fbshipit-source-id: 141926a4a001e23f982279cd7eedda2aa33d5e5a
1 parent 2760b20 commit 244c892

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

hyperactor_mesh/src/bootstrap.rs

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,31 +1719,25 @@ impl BootstrapProcManager {
17191719
let (_lines, _bytes) = t.abort().await;
17201720
}
17211721

1722+
let tail_str = if stderr_tail.is_empty() {
1723+
None
1724+
} else {
1725+
Some(stderr_tail.join("\n"))
1726+
};
1727+
17221728
match wait_res {
17231729
Ok(status) => {
17241730
if let Some(sig) = status.signal() {
17251731
let _ = handle.mark_killed(sig, status.core_dumped());
17261732
if let Ok(mut table) = pid_table.lock() {
17271733
table.remove(&proc_id);
17281734
}
1729-
if stderr_tail.is_empty() {
1730-
tracing::debug!("proc {proc_id} killed by signal {sig}");
1731-
} else {
1732-
let tail = stderr_tail.join("\n");
1733-
tracing::debug!(
1734-
"proc {proc_id} killed by signal {sig}; stderr tail:\n{tail}"
1735-
);
1736-
}
1735+
tracing::debug!(tail = tail_str, "proc {proc_id} killed by signal {sig}");
17371736
} else if let Some(code) = status.code() {
1738-
let _ = handle.mark_stopped(code, stderr_tail.clone());
1737+
let _ = handle.mark_stopped(code, stderr_tail);
17391738
if let Ok(mut table) = pid_table.lock() {
17401739
table.remove(&proc_id);
17411740
}
1742-
let tail_str = if stderr_tail.is_empty() {
1743-
None
1744-
} else {
1745-
Some(stderr_tail.join("\n"))
1746-
};
17471741
if code == 0 {
17481742
tracing::debug!(%proc_id, exit_code = code, tail = tail_str.as_deref(), "proc exited");
17491743
} else {
@@ -1754,32 +1748,22 @@ impl BootstrapProcManager {
17541748
false,
17551749
"unreachable: process terminated with neither signal nor exit code"
17561750
);
1757-
tracing::error!(
1758-
"proc {proc_id}: unreachable exit status (no code, no signal)"
1759-
);
17601751
let _ = handle.mark_failed("process exited with unknown status");
17611752
if let Ok(mut table) = pid_table.lock() {
17621753
table.remove(&proc_id);
17631754
}
1764-
if stderr_tail.is_empty() {
1765-
tracing::warn!("proc {proc_id} unknown exit");
1766-
} else {
1767-
let tail = stderr_tail.join("\n");
1768-
tracing::warn!("proc {proc_id} unknown exit; stderr tail:\n{tail}");
1769-
}
1755+
tracing::error!(
1756+
tail = tail_str,
1757+
"proc {proc_id} unknown exit: unreachable exit status (no code, no signal)"
1758+
);
17701759
}
17711760
}
17721761
Err(e) => {
17731762
let _ = handle.mark_failed(format!("wait_inner() failed: {e}"));
17741763
if let Ok(mut table) = pid_table.lock() {
17751764
table.remove(&proc_id);
17761765
}
1777-
if stderr_tail.is_empty() {
1778-
tracing::info!("proc {proc_id} wait failed");
1779-
} else {
1780-
let tail = stderr_tail.join("\n");
1781-
tracing::info!("proc {proc_id} wait failed; stderr tail:\n{tail}");
1782-
}
1766+
tracing::info!(tail = tail_str, "proc {proc_id} wait failed");
17831767
}
17841768
}
17851769
});

0 commit comments

Comments
 (0)