From e1167f5e1210e0526e8a2992ecb679d5a9b04e70 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Tue, 22 Jul 2025 22:44:43 +0000 Subject: [PATCH 01/15] fix: correctly close HTTP-related CRT resources in native sourceset --- .../aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt | 8 +++++++- .../runtime/http/engine/crt/ConnectionManager.kt | 15 +++++++++++---- .../runtime/http/engine/crt/CrtHttpEngine.kt | 3 ++- .../http/engine/DefaultHttpEngineNative.kt | 7 ++++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt index cdcceaf596..269dcdb5ee 100644 --- a/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt +++ b/runtime/crt-util/jvmAndNative/src/aws/smithy/kotlin/runtime/crt/SdkDefaultIO.kt @@ -14,33 +14,39 @@ private const val DEFAULT_EVENT_LOOP_THREAD_COUNT: Int = 1 /** * Default (CRT) IO used by the SDK when not configured manually/directly */ +@Deprecated("This API is no longer used by the SDK and will be removed in version 1.6.x") @InternalApi public object SdkDefaultIO { /** * The default event loop group to run IO on */ + @Deprecated("This API is no longer used by the SDK and will be removed in version 1.6.x") public val EventLoop: EventLoopGroup by lazy { - // TODO - can we register shutdown in appropriate runtimes (e.g. jvm: addShutdown, native: atexit(), etc) when/if these lazy block(s) run? EventLoopGroup(DEFAULT_EVENT_LOOP_THREAD_COUNT) } /** * The default host resolver to resolve DNS queries with */ + @Deprecated("This API is no longer used by the SDK and will be removed in version 1.6.x") public val HostResolver: HostResolver by lazy { + @Suppress("DEPRECATION") HostResolver(EventLoop) } /** * The default client bootstrap */ + @Deprecated("This API is no longer used by the SDK and will be removed in version 1.6.x") public val ClientBootstrap: ClientBootstrap by lazy { + @Suppress("DEPRECATION") ClientBootstrap(EventLoop, HostResolver) } /** * The default TLS context */ + @Deprecated("This API is no longer used by the SDK and will be removed in version 1.6.x") public val TlsContext: TlsContext by lazy { TlsContext(TlsContextOptions.defaultClient()) } diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt index 081fe768f4..4b4fe5504c 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/ConnectionManager.kt @@ -5,11 +5,11 @@ package aws.smithy.kotlin.runtime.http.engine.crt import aws.sdk.kotlin.crt.http.* +import aws.sdk.kotlin.crt.io.ClientBootstrap import aws.sdk.kotlin.crt.io.SocketOptions import aws.sdk.kotlin.crt.io.TlsContext import aws.sdk.kotlin.crt.io.TlsContextOptionsBuilder import aws.sdk.kotlin.crt.io.Uri -import aws.smithy.kotlin.runtime.crt.SdkDefaultIO import aws.smithy.kotlin.runtime.http.HttpErrorCode import aws.smithy.kotlin.runtime.http.HttpException import aws.smithy.kotlin.runtime.http.engine.ProxyConfig @@ -39,8 +39,11 @@ internal class ConnectionManager( .build() .let(::CrtTlsContext) + private val manageClientBootstrap = config.clientBootstrap == null + private val clientBootstrap = config.clientBootstrap ?: ClientBootstrap() + private val options = HttpClientConnectionManagerOptionsBuilder().apply { - clientBootstrap = config.clientBootstrap ?: SdkDefaultIO.ClientBootstrap + clientBootstrap = this@ConnectionManager.clientBootstrap tlsContext = crtTlsContext manualWindowManagement = true socketOptions = SocketOptions( @@ -55,7 +58,7 @@ internal class ConnectionManager( private val connManagers = mutableMapOf() private val mutex = Mutex() - public suspend fun acquire(request: HttpRequest): HttpClientConnection { + suspend fun acquire(request: HttpRequest): HttpClientConnection { val proxyConfig = config.proxySelector.select(request.url) val manager = getManagerForUri(request.uri, proxyConfig) @@ -88,6 +91,7 @@ internal class ConnectionManager( throw httpEx } } + private suspend fun getManagerForUri(uri: Uri, proxyConfig: ProxyConfig): HttpClientConnectionManager = mutex.withLock { connManagers.getOrPut(uri.authority) { val connOpts = options.apply { @@ -109,9 +113,12 @@ internal class ConnectionManager( HttpClientConnectionManager(connOpts) } } + override fun close() { connManagers.forEach { entry -> entry.value.close() } crtTlsContext.close() + + if (manageClientBootstrap) clientBootstrap.close() } private inner class LeasedConnection(private val delegate: HttpClientConnection) : HttpClientConnection by delegate { @@ -127,7 +134,7 @@ internal class ConnectionManager( } private fun toCrtTlsVersion(sdkTlsVersion: SdkTlsVersion?): CrtTlsVersion = when (sdkTlsVersion) { - null -> aws.sdk.kotlin.crt.io.TlsVersion.SYS_DEFAULT + null -> CrtTlsVersion.SYS_DEFAULT TlsVersion.TLS_1_0 -> CrtTlsVersion.TLSv1 TlsVersion.TLS_1_1 -> CrtTlsVersion.TLS_V1_1 TlsVersion.TLS_1_2 -> CrtTlsVersion.TLS_V1_2 diff --git a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt index 40a38a9a90..de0e3b5457 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-crt/jvmAndNative/src/aws/smithy/kotlin/runtime/http/engine/crt/CrtHttpEngine.kt @@ -15,9 +15,10 @@ import aws.smithy.kotlin.runtime.io.internal.SdkDispatchers import aws.smithy.kotlin.runtime.operation.ExecutionContext import aws.smithy.kotlin.runtime.telemetry.logging.logger import aws.smithy.kotlin.runtime.time.Instant -import kotlinx.coroutines.* +import kotlinx.coroutines.job import kotlinx.coroutines.sync.Semaphore import kotlinx.coroutines.sync.withPermit +import kotlinx.coroutines.withContext internal const val DEFAULT_WINDOW_SIZE_BYTES: Int = 16 * 1024 internal const val CHUNK_BUFFER_SIZE: Long = 64 * 1024 diff --git a/runtime/protocol/http-client-engines/http-client-engine-default/native/src/aws/smithy/kotlin/runtime/http/engine/DefaultHttpEngineNative.kt b/runtime/protocol/http-client-engines/http-client-engine-default/native/src/aws/smithy/kotlin/runtime/http/engine/DefaultHttpEngineNative.kt index 6c0a4af219..7f74397245 100644 --- a/runtime/protocol/http-client-engines/http-client-engine-default/native/src/aws/smithy/kotlin/runtime/http/engine/DefaultHttpEngineNative.kt +++ b/runtime/protocol/http-client-engines/http-client-engine-default/native/src/aws/smithy/kotlin/runtime/http/engine/DefaultHttpEngineNative.kt @@ -7,4 +7,9 @@ package aws.smithy.kotlin.runtime.http.engine import aws.smithy.kotlin.runtime.http.engine.crt.CrtHttpEngine -internal actual fun newDefaultHttpEngine(block: (HttpClientEngineConfig.Builder.() -> Unit)?): CloseableHttpClientEngine = CrtHttpEngine() +internal actual fun newDefaultHttpEngine( + block: (HttpClientEngineConfig.Builder.() -> Unit)?, +): CloseableHttpClientEngine = when (block) { + null -> CrtHttpEngine() + else -> CrtHttpEngine(block) +} From 859778d52ba3370871c9a05675ea98e9c7406e84 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 16:09:50 +0000 Subject: [PATCH 02/15] retrigger CI From 0c5c27b28c1be070f33d1c676d58f361e2fb9883 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 17:20:37 +0000 Subject: [PATCH 03/15] =?UTF-8?q?retrigger=20CI=20=C3=97=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 722b6bec33a43e684c36fcdba4c6d8324db9d266 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 17:26:25 +0000 Subject: [PATCH 04/15] =?UTF-8?q?retrigger=20CI=20=C3=97=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 3920ba7bfdc58895232c17aed3891620684baac6 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:06:52 +0000 Subject: [PATCH 05/15] =?UTF-8?q?retrigger=20CI=20=C3=97=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From c6e41a37b5431f7340c47ed010e4e3f1bd92e4ec Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:09:38 +0000 Subject: [PATCH 06/15] =?UTF-8?q?retrigger=20CI=20=C3=97=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From fe9615bd199b5270ef619d38300506d5f63c7e51 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:23:27 +0000 Subject: [PATCH 07/15] attempt to add debug messaging to workflow --- .github/workflows/artifact-size-metrics.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index cd5b193179..00d364dcff 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -14,6 +14,11 @@ permissions: pull-requests: write jobs: + debug-artifact-size-metrics: + runs-on: ubuntu-latest + steps: + - name: Echo event name + run: echo "${{ github.event_name }}" release-metrics: if: github.event_name == 'release' runs-on: ubuntu-latest From e958a2fcb8009e1e83557dcac86b3da50df56ddc Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:31:39 +0000 Subject: [PATCH 08/15] maybe fixing a typo? --- .github/workflows/artifact-size-metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index 00d364dcff..e2b399ee31 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -51,7 +51,7 @@ jobs: - name: Checkout Sources uses: actions/checkout@v4 - name: Setup build - uses: .github/actions/setup-build + uses: ./.github/actions/setup-build - name: Configure JDK uses: actions/setup-java@v3 with: From 9ce1b9cddca2a99a1626acfd93306d054dda0c5b Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:36:40 +0000 Subject: [PATCH 09/15] remove debug message; change path name again --- .github/workflows/artifact-size-metrics.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index e2b399ee31..63bff248a0 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -14,11 +14,6 @@ permissions: pull-requests: write jobs: - debug-artifact-size-metrics: - runs-on: ubuntu-latest - steps: - - name: Echo event name - run: echo "${{ github.event_name }}" release-metrics: if: github.event_name == 'release' runs-on: ubuntu-latest @@ -51,7 +46,7 @@ jobs: - name: Checkout Sources uses: actions/checkout@v4 - name: Setup build - uses: ./.github/actions/setup-build + uses: ./smithy-kotlin/.github/actions/setup-build - name: Configure JDK uses: actions/setup-java@v3 with: From e00033544bd758cd008a4e3fadeb1911fa5d1aef Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:39:47 +0000 Subject: [PATCH 10/15] reverting to ./. notation --- .github/workflows/artifact-size-metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index 63bff248a0..efeae27fbf 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -46,7 +46,7 @@ jobs: - name: Checkout Sources uses: actions/checkout@v4 - name: Setup build - uses: ./smithy-kotlin/.github/actions/setup-build + uses: ./.github/actions/setup-build - name: Configure JDK uses: actions/setup-java@v3 with: From 7d84b5ec51d95894d2f3eb438512f3f149ed913d Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:49:16 +0000 Subject: [PATCH 11/15] checkout smithy-kotlin in dedicated subdirectory --- .github/workflows/artifact-size-metrics.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index efeae27fbf..b5d9092397 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -45,6 +45,8 @@ jobs: steps: - name: Checkout Sources uses: actions/checkout@v4 + with: + path: smithy-kotlin - name: Setup build uses: ./.github/actions/setup-build - name: Configure JDK From 46c6ca0fa597c8896f0b39ae5e8e09663922b882 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:50:45 +0000 Subject: [PATCH 12/15] qualifying path name in uses: --- .github/workflows/artifact-size-metrics.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index b5d9092397..a3f73a3a5c 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -48,7 +48,7 @@ jobs: with: path: smithy-kotlin - name: Setup build - uses: ./.github/actions/setup-build + uses: ./smithy-kotlin/.github/actions/setup-build - name: Configure JDK uses: actions/setup-java@v3 with: From 9b6478ff726acceef4fc5253f6b2cfcbb6b705ef Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Wed, 30 Jul 2025 21:09:22 +0000 Subject: [PATCH 13/15] update Configure Gradle action to use nested dir --- .github/workflows/artifact-size-metrics.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index a3f73a3a5c..b66d894a23 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -62,6 +62,8 @@ jobs: aws-region: us-west-2 - name: Configure Gradle uses: awslabs/aws-kotlin-repo-tools/.github/actions/configure-gradle@main + with: + working-directory: smithy-kotlin - name: Generate Artifact Size Metrics run: ./gradlew -Paws.kotlin.native=false artifactSizeMetrics - name: Analyze Artifact Size Metrics From ac08c9421bc1b55c7956d904d1753f5da1887363 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:38:03 +0000 Subject: [PATCH 14/15] =?UTF-8?q?retrigger=20CI=20=C3=97=20=E2=88=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From f60ccbf7a01a5743494e362508406d0c17d0228b Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:38:54 +0000 Subject: [PATCH 15/15] ...and re-add working directories --- .github/workflows/artifact-size-metrics.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/artifact-size-metrics.yml b/.github/workflows/artifact-size-metrics.yml index b66d894a23..815662b755 100644 --- a/.github/workflows/artifact-size-metrics.yml +++ b/.github/workflows/artifact-size-metrics.yml @@ -66,14 +66,17 @@ jobs: working-directory: smithy-kotlin - name: Generate Artifact Size Metrics run: ./gradlew -Paws.kotlin.native=false artifactSizeMetrics + working-directory: smithy-kotlin - name: Analyze Artifact Size Metrics run: ./gradlew analyzeArtifactSizeMetrics - + working-directory: smithy-kotlin - name: Show Results uses: awslabs/aws-kotlin-repo-tools/.github/actions/artifact-size-metrics/show-results@main - + with: + working-directory: smithy-kotlin - name: Evaluate if: ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }} + working-directory: smithy-kotlin run: | cd build/reports/metrics cat has-significant-change.txt | grep false || {