Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/desktop_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ impl PortalDesktop {
// that locking or a failed initialization releases the inhibition.
let mut _inhibitor: Option<IdleGuard> = 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); }
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/portal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
Loading