Skip to content

Commit 3e9d1d2

Browse files
jif-oaicopyberry
authored andcommitted
Avoid nested read locking when rendering browser sign-in (#47861)
## Why `render_ref` already holds a read lock on `sign_in_state`. Acquiring another read lock in `render_continue_in_browser` can deadlock when a writer is waiting. ## What changed Pass the borrowed `ContinueInBrowserState` from `render_ref` into the browser sign-in renderer instead of reading the lock again. ## Testing Update the existing narrow-width browser sign-in test to exercise `render_ref`, retaining checks for the full OSC 8 authentication link, device-code guidance, and cancellation footer. GitOrigin-RevId: ba83e212d510627be9dfd068c8d7318da32a1749
1 parent 58838df commit 3e9d1d2

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,12 @@ impl AuthModeWidget {
553553
.render(area, buf);
554554
}
555555

556-
fn render_continue_in_browser(&self, area: Rect, buf: &mut Buffer) {
556+
fn render_continue_in_browser(
557+
&self,
558+
area: Rect,
559+
buf: &mut Buffer,
560+
state: &ContinueInBrowserState,
561+
) {
557562
let mut spans = vec![" ".into()];
558563
if self.animations_enabled && !self.animations_suppressed.get() {
559564
// Schedule a follow-up frame to keep the shimmer animation going.
@@ -568,10 +573,7 @@ impl AuthModeWidget {
568573
}
569574
let mut lines = vec![spans.into(), "".into()];
570575

571-
let sign_in_state = self.sign_in_state.read().unwrap();
572-
let auth_url = if let SignInState::ChatGptContinueInBrowser(state) = &*sign_in_state
573-
&& !state.auth_url.is_empty()
574-
{
576+
let auth_url = if !state.auth_url.is_empty() {
575577
lines.push(" If the link doesn't open automatically, open the following link to authenticate:".into());
576578
lines.push("".into());
577579
lines.push(Line::from(vec![
@@ -1053,8 +1055,8 @@ impl WidgetRef for AuthModeWidget {
10531055
SignInState::PickMode => {
10541056
self.render_pick_mode(area, buf);
10551057
}
1056-
SignInState::ChatGptContinueInBrowser(_) => {
1057-
self.render_continue_in_browser(area, buf);
1058+
SignInState::ChatGptContinueInBrowser(state) => {
1059+
self.render_continue_in_browser(area, buf, state);
10581060
}
10591061
SignInState::ChatGptDeviceCode(state) => {
10601062
headless_chatgpt_login::render_device_code_login(self, area, buf, state);
@@ -1366,7 +1368,7 @@ mod tests {
13661368
let height = 30;
13671369
let area = Rect::new(0, 0, width, height);
13681370
let mut buf = Buffer::empty(area);
1369-
widget.render_continue_in_browser(area, &mut buf);
1371+
widget.render_ref(area, &mut buf);
13701372

13711373
let found = collect_osc8_chars(&buf, area, PRODUCTION_LENGTH_AUTH_URL);
13721374
assert_eq!(
@@ -1381,7 +1383,7 @@ mod tests {
13811383
terminal.set_viewport_area(area);
13821384

13831385
terminal
1384-
.draw(|frame| widget.render_continue_in_browser(area, frame.buffer_mut()))
1386+
.draw(|frame| widget.render_ref(area, frame.buffer_mut()))
13851387
.expect("draw");
13861388

13871389
let contents = terminal.backend().to_string();

0 commit comments

Comments
 (0)