Refresh IAM token lazily so it survives a long process pause#179
Open
sergeynenashev wants to merge 1 commit into
Open
Refresh IAM token lazily so it survives a long process pause#179sergeynenashev wants to merge 1 commit into
sergeynenashev wants to merge 1 commit into
Conversation
The IAM bearer token was refreshed only by a background time.AfterFunc. That timer's deadline is measured against the monotonic clock. If the process is paused for a long time (e.g. a suspended or migrated VM), the monotonic clock does not advance during the pause while wall-clock time does, so the timer can fire too late and the token may already be expired by wall-clock time when execution resumes. S3 then rejects the request with 403. Additionally store the token deadline as a wall-clock value (time.Now().UnixNano(), which has no monotonic component) and lazily re-acquire the token from the request signer when that deadline is near. The signer runs on the hot path after the process resumes, so it is a best-effort trigger independent of the possibly-late timer. The background timer remains the primary refresh path; the lazy path uses a smaller margin and is only a safety net. Both refresh paths are serialized through a mutex, and the wall-clock deadline is read via an atomic on the lock-free fast path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The IAM bearer token was refreshed only by a background time.AfterFunc. That timer's deadline is measured against the monotonic clock. If the process is paused for a long time (e.g. a suspended or migrated VM), the monotonic clock does not advance during the pause while wall-clock time does, so the timer can fire too late and the token may already be expired by wall-clock time when execution resumes. S3 then rejects the request with 403.
Additionally store the token deadline as a wall-clock value (time.Now().UnixNano(), which has no monotonic component) and lazily re-acquire the token from the request signer when that deadline is near. The signer runs on the hot path after the process resumes, so it is a best-effort trigger independent of the possibly-late timer. The background timer remains the primary refresh path; the lazy path uses a smaller margin and is only a safety net. Both refresh paths are serialized through a mutex, and the wall-clock deadline is read via an atomic on the lock-free fast path.