Skip to content

Commit 2ab6f8f

Browse files
committed
Close stream on completion
1 parent 611c622 commit 2ab6f8f

File tree

1 file changed

+6
-5
lines changed
  • runtime/protocol/http-client-engines/http-client-engine-crt/jvm/src/aws/smithy/kotlin/runtime/http/engine/crt

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public class CrtHttpEngine(public override val config: CrtHttpEngineConfig) : Ht
6464
logger.trace { "Acquired connection ${conn.id}" }
6565

6666
val respHandler = SdkStreamResponseHandler(conn, callContext)
67-
callContext.job.invokeOnCompletion {
68-
logger.trace { "completing handler; cause=$it" }
69-
// ensures the stream is driven to completion regardless of what the downstream consumer does
70-
respHandler.complete()
71-
}
7267

7368
val reqTime = Instant.now()
7469
val engineRequest = request.toCrtRequest(callContext)
@@ -79,6 +74,12 @@ public class CrtHttpEngine(public override val config: CrtHttpEngineConfig) : Ht
7974
}
8075
}
8176

77+
callContext.job.invokeOnCompletion {
78+
// ensures the stream is driven to completion regardless of what the downstream consumer does
79+
stream.close()
80+
respHandler.complete()
81+
}
82+
8283
if (request.isChunked) {
8384
withContext(SdkDispatchers.IO) {
8485
stream.sendChunkedBody(request.body)

0 commit comments

Comments
 (0)