mirror of
https://github.com/openai/codex.git
synced 2026-11-20 23:08:21 +00:00
Make the managed app-server shutdown grace period configurable (#43572)
## Why Managed app-server shutdowns use a fixed 60-second grace period. Allow users to adjust how long shutdown waits before forcing the process to exit. ## What changed - Add `shutdownGraceSeconds` to daemon settings, accepting integers from 0 through 300 and defaulting to 60. Zero requests graceful shutdown and then forces termination immediately. - Apply the setting to managed app-server stops and restarts, including updater-triggered restarts, and extend the lifecycle lock timeout to accommodate the maximum grace period. - Keep `stop` usable with unreadable or invalid settings by falling back to the default grace period. ## Testing Add tests for setting defaults and bounds, invalid-value fallback, preservation when saving remote-control settings, graceful process exit, and forced termination with zero or finite grace periods. GitOrigin-RevId: 8627b391323cf27b40df96935a82e66aa715f572
This commit is contained in:
1 parent
98a5cb46b1
commit
a51608398d
6 files changed
+251
-17
No files matched your search
@@ -27,11 +27,14 @@ use managed_install::managed_codex_bin;
|
||||
use managed_install::managed_codex_version;
|
||||
use serde::Serialize;
|
||||
use settings::DaemonSettings;
|
||||
use settings::MAX_SHUTDOWN_GRACE_SECONDS;
|
||||
use tokio::time::sleep;
|
||||
|
||||
const START_POLL_INTERVAL: Duration = Duration::from_millis(50);
|
||||
const START_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
const OPERATION_LOCK_TIMEOUT: Duration = Duration::from_secs(75);
|
||||
// Leave room for the longest graceful stop, forced-exit check, and restart.
|
||||
const OPERATION_LOCK_TIMEOUT: Duration =
|
||||
Duration::from_secs(MAX_SHUTDOWN_GRACE_SECONDS as u64 + 75);
|
||||
const PID_FILE_NAME: &str = "app-server.pid";
|
||||
const UPDATE_PID_FILE_NAME: &str = "app-server-updater.pid";
|
||||
const OPERATION_LOCK_FILE_NAME: &str = "daemon.lock";
|
||||
@@ -383,7 +386,9 @@ impl Daemon {
|
||||
|
||||
self.ensure_managed_codex_bin()?;
|
||||
if let Some(backend) = self.running_backend_instance(&settings).await? {
|
||||
backend.stop().await?;
|
||||
backend
|
||||
.stop_with_grace(settings.shutdown_grace_seconds)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let pid = self.start_managed_backend(&settings).await?;
|
||||
@@ -451,7 +456,9 @@ impl Daemon {
|
||||
RestartDecision::Restart => {
|
||||
#[cfg(windows)]
|
||||
backend::windows::ensure_detached_launch(managed_codex_bin)?;
|
||||
backend.stop().await?;
|
||||
backend
|
||||
.stop_with_grace(settings.shutdown_grace_seconds)
|
||||
.await?;
|
||||
let _ = self
|
||||
.start_managed_backend_with_bin(&settings, managed_codex_bin)
|
||||
.await?;
|
||||
@@ -480,10 +487,11 @@ impl Daemon {
|
||||
}
|
||||
|
||||
async fn stop(&self) -> Result<LifecycleOutput> {
|
||||
// Stopping a managed process does not require readable settings.
|
||||
let settings = DaemonSettings::default();
|
||||
let settings = DaemonSettings::load_for_stop(&self.settings_file).await;
|
||||
if let Some(backend) = self.running_backend_instance(&settings).await? {
|
||||
backend.stop().await?;
|
||||
backend
|
||||
.stop_with_grace(settings.shutdown_grace_seconds)
|
||||
.await?;
|
||||
return Ok(self
|
||||
.output(
|
||||
LifecycleStatus::Stopped,
|
||||
@@ -646,7 +654,9 @@ impl Daemon {
|
||||
settings.save(&self.settings_file).await?;
|
||||
|
||||
let app_server_version = if let Some(backend) = backend {
|
||||
backend.stop().await?;
|
||||
backend
|
||||
.stop_with_grace(settings.shutdown_grace_seconds)
|
||||
.await?;
|
||||
let _ = self.start_managed_backend(&settings).await?;
|
||||
let info = self.wait_until_ready().await?;
|
||||
if let Err(err) = self.ensure_managed_updater(&settings).await {
|
||||
@@ -685,7 +695,9 @@ impl Daemon {
|
||||
.stop()
|
||||
.await?;
|
||||
if let Some(backend) = self.running_backend_instance(&settings).await? {
|
||||
backend.stop().await?;
|
||||
backend
|
||||
.stop_with_grace(settings.shutdown_grace_seconds)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let backend = backend::pid_backend(self.backend_paths(&settings));
|
||||
|
||||
Reference in new issue
Block a user