Skip to content

fix(device): cap login poll sleep at expiry deadline - #118

Open
sathishking wants to merge 1 commit into
prooflinedev:mainfrom
sathishking:fix/device-login-final-poll
Open

sathishking wants to merge 1 commit into
prooflinedev:mainfrom
sathishking:fix/device-login-final-poll

Conversation

@sathishking

Copy link
Copy Markdown

Problem

In src/device.rs, device::finish slept a full interval before checking Instant::now() >= deadline:

tokio::time::sleep(Duration::from_secs(interval)).await;
if tokio::time::Instant::now() >= deadline {
    return Err(DeviceError::Expired);
}

When remaining time before expires_in was shorter than interval (including after slow_down increased interval, or when expires_in <= interval), finish slept past deadline and returned DeviceError::Expired without polling in the final window—dropping approvals completed right before expiry.

What changed

  • src/device.rs (device::finish):
    • Check current >= deadline before sleeping so an already-expired challenge returns DeviceError::Expired with zero polls.
    • Cap each sleep at deadline using checked_add and tokio::time::sleep_until(wake) so the final poll runs before expiring.
  • src/device.rs (tests::finish_polls_at_deadline_instead_of_sleeping_past_expiry):
    • Added a paused-clock test against a loopback /auth/device/token server verifying late approvals at deadline succeed, persistent authorization_pending expires after the deadline poll without extra sleeps, and expires_in = 0 exits immediately with zero polls.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant