Skip to content

Commit bfcc35c

Browse files
authored
fix: Close CRT HttpStream on call completion (#1134)
1 parent 151d808 commit bfcc35c

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": "1ab4f8b7-5721-4024-a4dc-d0c595495bd2",
3+
"type": "bugfix",
4+
"description": "Close HttpStreams in CrtHttpEngine after call completion"
5+
}

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public class CrtHttpEngine(public override val config: CrtHttpEngineConfig) : Ht
7979
}
8080
}
8181

82+
callContext.job.invokeOnCompletion {
83+
stream.close()
84+
}
85+
8286
if (request.isChunked) {
8387
withContext(SdkDispatchers.IO) {
8488
stream.sendChunkedBody(request.body)

runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt/SdkStreamResponseHandler.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ internal class SdkStreamResponseHandler(
149149
}
150150

151151
// short circuit, stop buffering data and discard remaining incoming bytes
152-
if (isCancelled) return bodyBytesIn.len
152+
if (isCancelled) {
153+
crtStream?.close()
154+
stream.close()
155+
return bodyBytesIn.len
156+
}
153157

154158
val buffer = SdkBuffer().apply {
155159
val bytes = bodyBytesIn.readAll()
@@ -166,9 +170,11 @@ internal class SdkStreamResponseHandler(
166170
// stream is only valid until the end of this callback, ensure any further data being read downstream
167171
// doesn't call incrementWindow on a resource that has been free'd
168172
lock.withLock {
173+
crtStream?.close()
169174
crtStream = null
170175
streamCompleted = true
171176
}
177+
stream.close()
172178

173179
// close the body channel
174180
if (errorCode != 0) {

0 commit comments

Comments
 (0)