Skip to content

Commit 282a634

Browse files
committed
fix(manager): use floating point for refresh ratio
1 parent 3f6754f commit 282a634

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

manager/entraid_manager.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,9 @@ func (e *entraidTokenManager) durationToRenewal(t *token.Token) time.Duration {
272272
return 0
273273
}
274274

275-
// Calculate refresh time using integer math:
276-
// 1. TTL is already in milliseconds
277-
// 2. Multiply by refresh ratio (as integer percentage)
278-
// 3. Add to received time
279-
ttlMillis := t.TTL() // Already in milliseconds
280-
refreshRatioInt := int64(e.expirationRefreshRatio * 100) // Convert to integer percentage
281-
refreshMillis := (ttlMillis * refreshRatioInt) / 100 // Integer division for ratio
275+
ttlMillis := t.TTL() // Already in milliseconds
276+
// let's not lose the precision here, examples use 0.001, which would be lost with integer math
277+
refreshMillis := int64(float64(ttlMillis) * e.expirationRefreshRatio)
282278
refreshTimeMillis := t.ReceivedAt().UnixMilli() + refreshMillis
283279

284280
// Calculate time until refresh

0 commit comments

Comments
 (0)