Skip to content

Commit 87baacf

Browse files
committed
fix: correctly handle sequential calls to SingleFlightGroup
1 parent 8178808 commit 87baacf

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "065e6349-8e2a-403b-b588-067161f260fd",
3+
"type": "bugfix",
4+
"description": "Correctly handle sequential calls to `SingleFlightGroup`"
5+
}

runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/util/SingleFlightGroup.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public class SingleFlightGroup<T> {
5252
inFlight = deferred
5353
mu.unlock()
5454
runCatching { block() }.let { deferred.complete(it) }
55-
return deferred.await().getOrThrow()
55+
return deferred.await().also { inFlight = null }.getOrThrow()
5656
}
5757
}

runtime/runtime-core/common/test/aws/smithy/kotlin/runtime/util/SingleFlightGroupTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ class SingleFlightGroupTest {
109109
}
110110
}
111111
}
112+
113+
@Test
114+
fun testSequential() = runTest {
115+
val group = SingleFlightGroup<String>()
116+
val first = group.singleFlight { "Foo" }
117+
assertEquals("Foo", first)
118+
119+
val second = group.singleFlight { "Bar" }
120+
assertEquals("Bar", second) // Fails; second == "Foo"
121+
}
112122
}

0 commit comments

Comments
 (0)