Skip to content

Commit 36cda40

Browse files
committed
fix: tune clock drift for slow-mono case
Signed-off-by: Babak K. Shandiz <babakks@github.com>
1 parent cbeeb2f commit 36cda40

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

device/device_flow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func Wait(ctx context.Context, c httpClient, uri string, opts WaitOptions) (*api
257257
// should not cause slow_down errors, unless the slow monotonic clock
258258
// is still ticking faster than the OAuth server's clock. For such
259259
// cases we tolerate a few more slow-downs.
260-
if slowDowns > 2 && driftRatio > 0.05 || slowDowns > 4 && driftRatio < 0 {
260+
if slowDowns > 2 && driftRatio > 0.05 || slowDowns > 4 && driftRatio < -0.05 {
261261
return nil, fmt.Errorf("received too many slow_down responses; detected clock drift of roughly %.0f%% between monotonic and wall clocks; please ensure your system clock is accurate", driftRatio*100)
262262
}
263263

device/device_flow_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func TestPollToken(t *testing.T) {
707707
},
708708
},
709709
{
710-
name: "failure with multiple slow downs, due to high clock drift (mono slower)",
710+
name: "failure with multiple slow downs, due to high clock drift (mono faster)",
711711
args: args{
712712
http: apiClient{
713713
stubs: []apiStub{
@@ -815,10 +815,10 @@ func TestPollToken(t *testing.T) {
815815
Interval: 5,
816816
},
817817
newPoller: singletonFakePoller(6),
818-
calculateTimeDriftRatioF: newCalculateTimeDriftRatioStub(-0.01, -0.01, -0.01, -0.01, -0.01),
818+
calculateTimeDriftRatioF: newCalculateTimeDriftRatioStub(-0.051, -0.051, -0.051, -0.051, -0.051),
819819
},
820820
},
821-
wantErr: `received too many slow_down responses; detected clock drift of roughly -1% between monotonic and wall clocks; please ensure your system clock is accurate`,
821+
wantErr: `received too many slow_down responses; detected clock drift of roughly -5% between monotonic and wall clocks; please ensure your system clock is accurate`,
822822
posts: repeatPostArgs(6, postArgs{
823823
url: "https://github.com/oauth",
824824
params: url.Values{

0 commit comments

Comments
 (0)