File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -272,13 +272,14 @@ func (e *entraidTokenManager) durationToRenewal(t *token.Token) time.Duration {
272
272
return 0
273
273
}
274
274
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
+ // Example:
278
+ // ttlMillis = 10000
279
+ // e.expirationRefreshRatio = 0.001
280
+ // - with int math: 10000 * (0.001*100) = 0ms
281
+ // - with float math: 10000 * 0.001 = 10ms
282
+ refreshMillis := int64 (float64 (ttlMillis ) * e .expirationRefreshRatio )
282
283
refreshTimeMillis := t .ReceivedAt ().UnixMilli () + refreshMillis
283
284
284
285
// Calculate time until refresh
You can’t perform that action at this time.
0 commit comments