Unable to Customize Proxy or Create Client when Environment Variables are Invalid
austinarbor opened this issue · comments
Describe the bug
If the environment contains a "bad" variable for the Proxy, you are unable to build the client even if you override the proxy settings due to the default initialization logic.
Expected behavior
Overriding the proxy settings should allow you to successfully create a client
Current behavior
The builder throws an exception
Steps to Reproduce
// pretend there is an environment variable set `http_proxy=`
val client = DynamoDbClient {
// customize
}
The above throws an exception
java.lang.ExceptionInInitializerError
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine$Companion.invoke(OkHttpEngine.kt:38)
at aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngineJVMKt.newDefaultHttpEngine(DefaultHttpEngineJVM.kt:14)
at aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngineKt.DefaultHttpEngine(DefaultHttpEngine.kt:23)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineConstructor$1.invoke(HttpEngineConfigImpl.kt:20)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineConstructor$1.invoke(HttpEngineConfigImpl.kt:20)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineSupplier$1.invoke(HttpEngineConfigImpl.kt:21)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl$engineSupplier$1.invoke(HttpEngineConfigImpl.kt:21)
at aws.smithy.kotlin.runtime.http.engine.HttpEngineConfigImpl$BuilderImpl.buildHttpEngineConfig(HttpEngineConfigImpl.kt:75)
at aws.sdk.kotlin.services.dynamodb.DynamoDbClient$Config$Builder.buildHttpEngineConfig(DynamoDbClient.kt)
at aws.sdk.kotlin.services.dynamodb.DynamoDbClient$Config.<init>(DynamoDbClient.kt:202)
at aws.sdk.kotlin.services.dynamodb.DynamoDbClient$Config.<init>(DynamoDbClient.kt)
at aws.sdk.kotlin.services.dynamodb.DynamoDbClient$Config$Builder.build(DynamoDbClient.kt:370)
at aws.sdk.kotlin.services.dynamodb.DynamoDbClient$Config$Builder.build(DynamoDbClient.kt:244)
at aws.smithy.kotlin.runtime.client.AbstractSdkClientBuilder.build(AbstractSdkClientBuilder.kt:20)
at aws.smithy.kotlin.runtime.client.AbstractSdkClientBuilder.build(AbstractSdkClientBuilder.kt:13)
at aws.smithy.kotlin.runtime.client.SdkClientFactory$DefaultImpls.invoke(SdkClientFactory.kt:32)
at aws.sdk.kotlin.runtime.config.AbstractAwsSdkClientFactory.invoke(AbstractAwsSdkClientFactory.kt:44)
at com.workiva.callofduty.repo.ChannelRotationsRepoTest$client$1.invokeSuspend(ChannelRotationsRepoTest.kt:33)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
<trimmed>
Caused by: aws.smithy.kotlin.runtime.ClientException: Could not parse http_proxy="" into a valid proxy URL
at aws.smithy.kotlin.runtime.http.engine.EnvironmentProxySelectorKt.resolveProxyByEnvironment(EnvironmentProxySelector.kt:93)
at aws.smithy.kotlin.runtime.http.engine.EnvironmentProxySelectorKt.access$resolveProxyByEnvironment(EnvironmentProxySelector.kt:1)
at aws.smithy.kotlin.runtime.http.engine.EnvironmentProxySelector.<init>(EnvironmentProxySelector.kt:34)
at aws.smithy.kotlin.runtime.http.engine.EnvironmentProxySelector.<init>(EnvironmentProxySelector.kt:32)
at aws.smithy.kotlin.runtime.http.engine.HttpClientEngineConfigImpl$BuilderImpl.<init>(HttpClientEngineConfig.kt:222)
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineConfig$Builder.<init>(OkHttpEngineConfig.kt:47)
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngineConfig.<clinit>(OkHttpEngineConfig.kt:28)
... 108 more
Caused by: java.lang.IllegalArgumentException: Cannot parse "" as a URL
at aws.smithy.kotlin.runtime.net.url.Url$Companion.parse(Url.kt:84)
at aws.smithy.kotlin.runtime.net.url.Url$Companion.parse$default(Url.kt:48)
at aws.smithy.kotlin.runtime.http.engine.EnvironmentProxySelectorKt.resolveProxyByEnvironment(EnvironmentProxySelector.kt:90)
... 114 more
Caused by: java.lang.IllegalArgumentException: Cannot find any of [://]
at aws.smithy.kotlin.runtime.text.Scanner.requireAndSkip(Scanner.kt:138)
at aws.smithy.kotlin.runtime.net.url.Url$Companion.parse(Url.kt:51)
... 116 more
If you try and then override the proxy settings
val client = DynamoDbClient {
httpClient{
proxySelector = ProxySelector.NoProxy
}
}
// or
val cfg = OkHttpEngineConfig {proxySelector = ProxySelector.NoProxy}
val client = DynamoDbClient {
httpClient = OkHttpEngine(cfg)
}
These also throw the same exception because the default value in BuilderImpl
of proxySelector
is EnvironmentProxySelector()
so it gets invoked no matter what
Possible Solution
No response
Context
No response
AWS Kotlin SDK version used
1.1.15
Platform (JVM/JS/Native)
JVM
Operating System and version
MacOS 14.4.1
Thanks for the report! I'm able to replicate it and am working on a fix
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.