[client] Fix device flow polling interval defaults and slow_down handling - #7013
[client] Fix device flow polling interval defaults and slow_down handling#7013Optic00 wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughThe device authorization flow now normalizes polling intervals, defaults invalid values to five seconds, clamps oversized values, and adds five seconds for ChangesDevice Flow Polling Interval Update
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
client/internal/auth/device_flow_test.go (1)
339-341: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest cumulative
slow_downbehavior.This assertion verifies one five-second increment only. It does not verify that a second
slow_downuses the updated interval.Apply the helper twice and expect
2s → 7s → 12s, or add aWaitTokentest with two consecutiveslow_downresponses.Proposed test extension
func TestSlowDownDeviceFlowPollingInterval(t *testing.T) { - require.Equal(t, 7*time.Second, slowDownDeviceFlowPollingInterval(2*time.Second)) + interval := slowDownDeviceFlowPollingInterval(2 * time.Second) + require.Equal(t, 7*time.Second, interval) + require.Equal(t, 12*time.Second, slowDownDeviceFlowPollingInterval(interval)) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@client/internal/auth/device_flow_test.go` around lines 339 - 341, Extend TestSlowDownDeviceFlowPollingInterval to apply slowDownDeviceFlowPollingInterval cumulatively: start at 2 seconds, assert the first call returns 7 seconds, then pass that result into a second call and assert it returns 12 seconds.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@client/internal/auth/device_flow.go`:
- Around line 251-262: Bound device-flow polling durations in
initialDeviceFlowPollingInterval and slowDownDeviceFlowPollingInterval so
external interval values and repeated slow_down increments cannot overflow
time.Duration or produce non-positive durations before ticker creation/reset.
Validate and return an error, or clamp both results to a safe maximum duration
accepted by the surrounding polling flow, while preserving the default behavior
for non-positive initial values.
---
Nitpick comments:
In `@client/internal/auth/device_flow_test.go`:
- Around line 339-341: Extend TestSlowDownDeviceFlowPollingInterval to apply
slowDownDeviceFlowPollingInterval cumulatively: start at 2 seconds, assert the
first call returns 7 seconds, then pass that result into a second call and
assert it returns 12 seconds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 45aa81cd-fc70-438f-ba52-782ea59363aa
📒 Files selected for processing (2)
client/internal/auth/device_flow.goclient/internal/auth/device_flow_test.go
|



Describe your changes
The device authorization flow mishandled the polling interval in two RFC-relevant ways and also lacked bounds checks for values that cannot be represented safely as
time.Duration.intervalis optional in the device authorization response (RFC 8628, section 3.2). If an IdP omitted it, the field decoded to0, andWaitTokenpassed0intotime.NewTicker, which panics withnon-positive interval for NewTicker. Login against such an IdP crashed instead of polling.slow_downerror the interval was increased by 3 seconds. RFC 8628, section 3.5 requires the polling interval to be increased by 5 seconds for this and all subsequent requests. Each laterslow_downresponse applies the same rule again, so repeated responses increase the interval cumulatively.time.Duration, and repeatedslow_downincreases could overflow during addition.Changes:
initialDeviceFlowPollingIntervaluses the RFC's 5-second default whenintervalis omitted and decoded as zero. BecauseAuthFlowInfo.Intervalis anint, an explicit zero is indistinguishable from omission; non-positive values also fall back to 5 seconds as defensive hardening.deviceFlowPollingIntervalFromSecondsconverts positive values safely and saturates values above the largest whole-second duration representable bytime.Duration.slowDownDeviceFlowPollingIntervaladds 5 seconds for eachslow_downresponse when representable and saturates at the maximum positivetime.Duration.These helpers are unexported; production polling reaches them only through
WaitToken. The change touchesclient/internal/auth/device_flow.goand its test file only. No public API, gRPC protocol, CLI or service flag, JSON payload, persistence format, or PKCE behavior is affected.The tests are deterministic and cover omitted and provided intervals, non-positive values, maximum integer inputs, exact overflow boundaries, cumulative
slow_down, saturation behavior, canceled contexts, and ticker safety. They require no real sleeps, fake clocks, or new dependencies.Note on the last checklist item: this is a behavior fix, so the client's runtime polling behavior does change. The omitted-interval default and the five-second
slow_downincrease align the client with RFC 8628; handling explicit non-positive and unrepresentably large values is additional defensive hardening. I left that box unchecked rather than claim no behavior change. Happy to discuss if you want it handled differently.Issue ticket number and link
N/A
Stack
Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
N/A
Summary by CodeRabbit
slow_downresponses, including boundary cases.