Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/903848fb-77d4-4431-8a4e-abb52b25b7c8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "903848fb-77d4-4431-8a4e-abb52b25b7c8",
"type": "bugfix",
"description": "Fix concurrency issues with S3 Express credential caching"
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ internal class DefaultS3ExpressCredentialsProvider(
client.logger.trace { "Credentials for ${key.bucket} are expiring in ${it.expiringCredentials.expiresAt} and are within their refresh window, performing asynchronous refresh..." }
launch(coroutineContext) {
try {
it.sfg.singleFlight { createSessionCredentials(key, client) }
it.sfg.singleFlight {
// This coroutine/SFG may have started _after_ prior instances(s) finished, replacing
// the cached value already. To prevent re-refreshing it, we need to re-acquire the
// current cached value and verify whether it's expiring soon.
val currentCreds = credentialsCache.get(key)

if (currentCreds?.expiringCredentials?.isExpiringWithin(refreshBuffer) == true) {
createSessionCredentials(key, client)
} else {
it.expiringCredentials
}
}
} catch (e: Exception) {
client.logger.warn(e) { "Asynchronous refresh for ${key.bucket} failed." }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class DefaultS3ExpressCredentialsProviderTest {
}

@Test
@Ignore // FIXME flaky test temporarily disabled to unblock preview builds
fun testAsyncRefreshDebounce() = runTest {
val timeSource = TestTimeSource()
val clock = ManualClock()
Expand Down
Loading