diff --git a/src/desktop_session.rs b/src/desktop_session.rs index 70883a7..dc45a00 100644 --- a/src/desktop_session.rs +++ b/src/desktop_session.rs @@ -281,7 +281,10 @@ impl PortalDesktop { // that locking or a failed initialization releases the inhibition. let mut _inhibitor: Option = None; loop { - if !owner.is_current() { return Ok(()); } + if !owner.is_current() { + log::info!("Portal maintain stopped: superseded by a newer desktop connection"); + return Ok(()); + } let state = *locked.borrow_and_update(); if state == Some(false) { defer_until_unlock = false; } if state != Some(false) && previous == Some(Some(false)) { self.pause(&owner); } @@ -294,7 +297,13 @@ impl PortalDesktop { if attempt_allowed(state, allow_locked) && !defer_until_unlock { // A fresh transition into an attempted state gets an immediate wake/recovery attempt. let force_wake = fresh_state(previous, state); - if force_wake { retry_at = Instant::now(); } + if force_wake { + retry_at = Instant::now(); + // One line per lock-state transition: connects that start locked only become + // picture-capable after the auto unlock, and this is the marker that the + // supervisor actually reacted to the unlock (its absence means the loop is dead). + log::info!("Portal desktop lock transition: state={state:?} defer={defer_until_unlock}"); + } let mut attempt_locked = locked.clone(); let outcome = tokio::select! { biased; @@ -394,6 +403,9 @@ impl PortalDesktop { // A new controller can arrive while the cached Portal handle is alive // but the display has gone to sleep without a lock transition. if healthy { return AttemptOutcome::Ready(screen, inhibitor); } + // Marks every real reopen: paired with the lock-transition log, the absence of an + // outcome after this line pins a stall to the blocking open/recovery worker below. + log::info!("Portal attempt: reopening the capture session (force_wake={force_wake})"); let worker_cancel = cancel.clone(); let result = tokio::task::spawn_blocking(move || { // The worker owns the gate until its real cleanup completes; a diff --git a/src/portal.rs b/src/portal.rs index 363e97a..a7d7528 100644 --- a/src/portal.rs +++ b/src/portal.rs @@ -547,11 +547,19 @@ mod native { use std::sync::atomic::Ordering; if cancelled.load(Ordering::Acquire) { return Err(super::PortalError { code: 13 }); } // Serialize with the encoder's stream-loss recovery: two openers would ask for consent twice. + // The wait is bounded: another opener (encoder reopen, consent rebuild) can hold this lock + // for as long as a consent dialog waits, and an unbounded spin here would leave the desktop + // supervisor's attempt silently running with no log and no frames until the viewer times out. + let lock_wait_deadline = std::time::Instant::now() + std::time::Duration::from_secs(15); let mut recovery = loop { match self.recovery.try_lock() { Ok(recovery) => break recovery, Err(TryLockError::WouldBlock) => { if cancelled.load(Ordering::Acquire) { return Err(super::PortalError { code: 13 }); } + if std::time::Instant::now() >= lock_wait_deadline { + log::warn!("Portal recovery lock held by another opener for 15s; retrying later"); + return Err(super::PortalError { code: 3 }); + } std::thread::sleep(std::time::Duration::from_millis(20)); } Err(TryLockError::Poisoned(_)) => return Err(super::PortalError { code: 3 }),