fix: make ShutdownHandle a private field of LoginServer (#2396)

Folds the top-level `shutdown()` function into a method of
`ShutdownHandle` and then simply stores `ShutdownHandle` on
`LoginServer` since the two fields it contains were always being used
together, anyway.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/2396).
* #2399
* #2398
* __->__ #2396
* #2395
* #2394
* #2393
* #2389
This commit is contained in:
Michael Bolin
2025-08-18 17:57:04 -07:00
committed by GitHub
parent 7f21634165
commit d5b42ba1ac
3 changed files with 13 additions and 19 deletions

View File

@@ -46,9 +46,8 @@ impl ServerOptions {
pub struct LoginServer { pub struct LoginServer {
pub auth_url: String, pub auth_url: String,
pub actual_port: u16, pub actual_port: u16,
shutdown_flag: Arc<tokio::sync::Notify>,
server_handle: tokio::task::JoinHandle<io::Result<()>>, server_handle: tokio::task::JoinHandle<io::Result<()>>,
server: Arc<Server>, shutdown_handle: ShutdownHandle,
} }
impl LoginServer { impl LoginServer {
@@ -59,14 +58,11 @@ impl LoginServer {
} }
pub fn cancel(&self) { pub fn cancel(&self) {
shutdown(&self.shutdown_flag, &self.server); self.shutdown_handle.shutdown();
} }
pub fn cancel_handle(&self) -> ShutdownHandle { pub fn cancel_handle(&self) -> ShutdownHandle {
ShutdownHandle { self.shutdown_handle.clone()
shutdown_notify: self.shutdown_flag.clone(),
server: self.server.clone(),
}
} }
} }
@@ -85,16 +81,12 @@ impl std::fmt::Debug for ShutdownHandle {
} }
impl ShutdownHandle { impl ShutdownHandle {
pub fn cancel(&self) { pub fn shutdown(&self) {
shutdown(&self.shutdown_notify, &self.server); self.shutdown_notify.notify_waiters();
self.server.unblock();
} }
} }
pub fn shutdown(shutdown_notify: &tokio::sync::Notify, server: &Server) {
shutdown_notify.notify_waiters();
server.unblock();
}
pub fn run_login_server( pub fn run_login_server(
opts: ServerOptions, opts: ServerOptions,
shutdown_flag: Option<Arc<tokio::sync::Notify>>, shutdown_flag: Option<Arc<tokio::sync::Notify>>,
@@ -181,8 +173,10 @@ pub fn run_login_server(
auth_url, auth_url,
actual_port, actual_port,
server_handle, server_handle,
shutdown_flag: shutdown_notify, shutdown_handle: ShutdownHandle {
server, shutdown_notify,
server,
},
}) })
} }

View File

@@ -66,7 +66,7 @@ struct ActiveLogin {
impl ActiveLogin { impl ActiveLogin {
fn drop(&self) { fn drop(&self) {
self.shutdown_handle.cancel(); self.shutdown_handle.shutdown();
} }
} }
@@ -190,7 +190,7 @@ impl CodexMessageProcessor {
Ok(Err(err)) => (false, Some(format!("Login server error: {err}"))), Ok(Err(err)) => (false, Some(format!("Login server error: {err}"))),
Err(_elapsed) => { Err(_elapsed) => {
// Timeout: cancel server and report // Timeout: cancel server and report
shutdown_handle.cancel(); shutdown_handle.shutdown();
(false, Some("Login timed out".to_string())) (false, Some("Login timed out".to_string()))
} }
}; };

View File

@@ -50,7 +50,7 @@ pub(crate) struct ContinueInBrowserState {
impl Drop for ContinueInBrowserState { impl Drop for ContinueInBrowserState {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(flag) = &self.shutdown_handle { if let Some(flag) = &self.shutdown_handle {
flag.cancel(); flag.shutdown();
} }
} }
} }