Skip to content

Commit d5b42ba

Browse files
authored
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
1 parent 7f21634 commit d5b42ba

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

codex-rs/login/src/server.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ impl ServerOptions {
4646
pub struct LoginServer {
4747
pub auth_url: String,
4848
pub actual_port: u16,
49-
shutdown_flag: Arc<tokio::sync::Notify>,
5049
server_handle: tokio::task::JoinHandle<io::Result<()>>,
51-
server: Arc<Server>,
50+
shutdown_handle: ShutdownHandle,
5251
}
5352

5453
impl LoginServer {
@@ -59,14 +58,11 @@ impl LoginServer {
5958
}
6059

6160
pub fn cancel(&self) {
62-
shutdown(&self.shutdown_flag, &self.server);
61+
self.shutdown_handle.shutdown();
6362
}
6463

6564
pub fn cancel_handle(&self) -> ShutdownHandle {
66-
ShutdownHandle {
67-
shutdown_notify: self.shutdown_flag.clone(),
68-
server: self.server.clone(),
69-
}
65+
self.shutdown_handle.clone()
7066
}
7167
}
7268

@@ -85,16 +81,12 @@ impl std::fmt::Debug for ShutdownHandle {
8581
}
8682

8783
impl ShutdownHandle {
88-
pub fn cancel(&self) {
89-
shutdown(&self.shutdown_notify, &self.server);
84+
pub fn shutdown(&self) {
85+
self.shutdown_notify.notify_waiters();
86+
self.server.unblock();
9087
}
9188
}
9289

93-
pub fn shutdown(shutdown_notify: &tokio::sync::Notify, server: &Server) {
94-
shutdown_notify.notify_waiters();
95-
server.unblock();
96-
}
97-
9890
pub fn run_login_server(
9991
opts: ServerOptions,
10092
shutdown_flag: Option<Arc<tokio::sync::Notify>>,
@@ -181,8 +173,10 @@ pub fn run_login_server(
181173
auth_url,
182174
actual_port,
183175
server_handle,
184-
shutdown_flag: shutdown_notify,
185-
server,
176+
shutdown_handle: ShutdownHandle {
177+
shutdown_notify,
178+
server,
179+
},
186180
})
187181
}
188182

codex-rs/mcp-server/src/codex_message_processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct ActiveLogin {
6666

6767
impl ActiveLogin {
6868
fn drop(&self) {
69-
self.shutdown_handle.cancel();
69+
self.shutdown_handle.shutdown();
7070
}
7171
}
7272

@@ -190,7 +190,7 @@ impl CodexMessageProcessor {
190190
Ok(Err(err)) => (false, Some(format!("Login server error: {err}"))),
191191
Err(_elapsed) => {
192192
// Timeout: cancel server and report
193-
shutdown_handle.cancel();
193+
shutdown_handle.shutdown();
194194
(false, Some("Login timed out".to_string()))
195195
}
196196
};

codex-rs/tui/src/onboarding/auth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) struct ContinueInBrowserState {
5050
impl Drop for ContinueInBrowserState {
5151
fn drop(&mut self) {
5252
if let Some(flag) = &self.shutdown_handle {
53-
flag.cancel();
53+
flag.shutdown();
5454
}
5555
}
5656
}

0 commit comments

Comments
 (0)