mirror of
https://github.com/openai/codex.git
synced 2026-11-24 15:21:20 +00:00
Support graceful daemon shutdown on Windows (#42364)
## Why Detached Windows processes cannot receive console signals, so app-server daemons need another way to enter the existing graceful and forced shutdown flow. ## What changed - Watch the path in `CODEX_DAEMON_SHUTDOWN_FILE` for a request addressed to the current process, and consume only a matching PID. - Race daemon shutdown requests with Ctrl-C on Windows while leaving unmanaged launches on the existing console-signal path. - Exercise the SIGTERM-equivalent graceful and forced WebSocket shutdown cases on Windows. ## Testing Added unit coverage ensuring inherited control paths and malformed requests cannot consume another process's shutdown request. GitOrigin-RevId: 426a3c12edc344802395d4d26288f2bb015c484f
This commit is contained in:
1 parent
577a4fcd06
commit
10aca93f18
7 files changed
+135
-9
No files matched your search
@@ -217,11 +217,28 @@ async fn shutdown_signal() -> IoResult<ShutdownSignal> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
#[cfg(windows)]
|
||||
{
|
||||
tokio::signal::ctrl_c()
|
||||
.await
|
||||
.map(|_| ShutdownSignal::Forceable)
|
||||
let console_signal = async {
|
||||
if tokio::signal::ctrl_c().await.is_err() {
|
||||
// A detached daemon has no console; keep its local control path active.
|
||||
std::future::pending::<()>().await;
|
||||
}
|
||||
};
|
||||
let daemon_signal = async {
|
||||
let result = codex_app_server_transport::daemon_shutdown_signal().await;
|
||||
// The processor retries listener errors; the updater instead needs
|
||||
// immediate errors from its nonblocking shutdown probe.
|
||||
if result.is_err() {
|
||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||
}
|
||||
result
|
||||
};
|
||||
tokio::select! {
|
||||
_ = console_signal => Ok(ShutdownSignal::Forceable),
|
||||
result = daemon_signal =>
|
||||
result.map(|_| ShutdownSignal::Forceable),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user