Skip to content

Commit 9f556fe

Browse files
committed
Fix StaticCredentialsProvider background refresh
- Add changeset for @ydbjs/auth patch - Await and swallow errors from #refreshToken to avoid synchronous disposal of the linked signal which aborted background refreshes Signed-off-by: Vladislav Polyakov <polRk@ydb.tech>
1 parent 89241c5 commit 9f556fe

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@ydbjs/auth': patch
3+
---
4+
5+
Fix `StaticCredentialsProvider` background token refresh being immediately cancelled
6+
7+
`#refreshTokenInBackground` previously used `void this.#refreshToken(linkedSignal.signal)` — fire-and-forget, so `using linkedSignal` stayed alive for the duration of the refresh. After the fix for the memory leak the call became `await this.#refreshToken(...)`, which caused `[Symbol.dispose]` to run synchronously at the end of the `async` function frame — before the refresh had a chance to complete — aborting the underlying `AbortController` and cancelling every background refresh immediately.

packages/auth/src/static.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class StaticCredentialsProvider extends CredentialsProvider {
152152
debug.log('starting background token refresh')
153153
using linkedSignal = linkSignals(signal, AbortSignal.timeout(BACKGROUND_REFRESH_TIMEOUT_MS))
154154

155-
void this.#refreshToken(linkedSignal.signal)
155+
await this.#refreshToken(linkedSignal.signal).catch(() => {})
156156
}
157157

158158
/**

packages/auth/vitest.config.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,29 @@ import { defineProject } from 'vitest/config'
22

33
export default defineProject({
44
test: {
5-
name: 'auth',
6-
include: ['src/**/*.test.ts'],
7-
environment: 'node',
5+
projects: [
6+
{
7+
test: {
8+
name: {
9+
label: 'uni',
10+
color: 'yellow',
11+
},
12+
include: ['src/**/*.test.ts'],
13+
environment: 'node',
14+
},
15+
},
16+
{
17+
test: {
18+
name: {
19+
label: 'int',
20+
color: 'blue',
21+
},
22+
include: ['tests/**/*.test.ts'],
23+
environment: 'node',
24+
testTimeout: 30000,
25+
globalSetup: '../../vitest.setup.ydb.ts',
26+
},
27+
},
28+
],
829
},
930
})

0 commit comments

Comments
 (0)