Commit 353aa27
authored
fix(auth): token refresh rapidly called unexpectedly (#6479)
## Problem:
getChatAuthState() is called in many places by the Q features
simultaneously,
this eventually triggers multiple calls to getToken() and if needed
refreshToken().
This resulted in refreshToken being spammed and the Identity team seeing
spikes in token refreshes
from clients.
## Solution:
Throttle getChatAuthState().
Throttling w/ leading: true, allows us to instantly return
a fresh result OR a cached result in the case we are throttled. Debounce
on the
other hand would cause callers to hang since they have to wait for
debounce to timeout.
Also, we put a debounce on getToken() before in #6282 but this did not
work since a new
SsoAccessToken instance is created each time the offending code flow
triggered (we could
look to cache the instance instead which would enable the getToken()
debounce to be useful.
### Testing
To test the difference after adding the throttle:
- Add log statements to `getToken()`
- Set an expired date in the SSO cache for both token expiration +
client registration expiration
- Use chat
What would happen is that without throttle it would trigger
getChatAuthState() many times, likely due to the connection
becoming invalid and sending an event to all Q features, causing each of
them to call getChatAuthState() at the same time.
But when the throttle was added, the amount of these calls dropped to at
most 2.
Signed-off-by: nkomonen-amazon <[email protected]>
---
- Treat all work as PUBLIC. Private `feature/x` branches will not be
squash-merged at release time.
- Your code changes must meet the guidelines in
[CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines).
- License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.
---------
Signed-off-by: nkomonen-amazon <[email protected]>1 parent 928593c commit 353aa27
File tree
4 files changed
+18
-30
lines changed- packages
- amazonq/src
- core/src
- auth/sso
- codewhisperer/util
- test/credentials/sso
4 files changed
+18
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | 100 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 101 | | |
115 | 102 | | |
116 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
405 | 420 | | |
406 | 421 | | |
407 | | - | |
| 422 | + | |
408 | 423 | | |
409 | 424 | | |
410 | 425 | | |
| |||
Lines changed: 0 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | 159 | | |
174 | 160 | | |
175 | 161 | | |
| |||
0 commit comments