degreat
09/19/2020, 2:21 PMaarjav
09/20/2020, 1:18 AMJohn O'Reilly
09/21/2020, 7:05 AMHttpClient
to apply different types of auths to different requests?peekandpoke
09/22/2020, 6:43 AMMouaad
09/22/2020, 8:57 AMgotoOla
09/22/2020, 9:08 AMsuspend fun main() {
val server = embeddedServer(Netty, port = 8099) {
routing {
route("/") {
getAndReportMetrics("/test") {
println("received a request")
delay(5000)
it.respondText { "test" }
}
}
}
addCallMetrics()
}.start()
val client = createHttpClient()
(1..7).map {
println("Sending $it request")
GlobalScope.async {
client.get<HttpResponse>("<http://localhost:8099/test>")
}
}.awaitAll()
}
fun createHttpClient(
socketTimeoutMs: Long = 30_000,
connectionTimeoutMs: Long = 30_000,
connectionRequestTimeoutMs: Long = 30_000
): HttpClient {
return HttpClient(OkHttp) {
install(HttpTimeout) {
connectTimeoutMillis = connectionTimeoutMs
requestTimeoutMillis = connectionRequestTimeoutMs
socketTimeoutMillis = socketTimeoutMs
}
engine {
config {
// <https://github.com/ktorio/ktor/issues/1708>
retryOnConnectionFailure(true)
}
}
expectSuccess = false
}
}
ribesg
09/22/2020, 1:19 PMbsimmons
09/22/2020, 2:44 PMrunBlocking { ... }
test and it just blocks until the request times out. Any ideas on why this is happening?ribesg
09/23/2020, 10:48 AMlouiscad
09/23/2020, 12:24 PMChris Fillmore
09/23/2020, 6:43 PMChristian Jensen
09/24/2020, 5:28 PMimplementation("io.ktor:ktor-client-ios:$ktorVersion")
.
Isn't there any ios dependecies for io.ktor:ktor-client-serialization
and io.ktor:ktor-client-json
for Ktor version 1.4.0?Thomas
09/24/2020, 6:40 PMIos
engine from Dispatchers.Default
is supported, too? I tried that and get an IncorrectDereferenceException
from Ktor code. When I modify the Ktor io.ktor.client.engine.ios.IosClientEngine
code (and related files in the same package) by adding some freeze()
calls, it works fine when called from Dispatchers.Default
. Is this expected behaviour at this time?tylerwilson
09/24/2020, 11:34 PMPierre Marais
09/25/2020, 8:02 AMVarvara
09/25/2020, 8:03 AMOleg Yukhnevich
09/25/2020, 9:27 AMSocket.close
. BTW, what is the best way to close client and server TCP? (seems like order of calling close matters some how)John O'Reilly
09/25/2020, 6:53 PM> Could not find ktor-client-core-1.4.1.jar (io.ktor:ktor-client-core:1.4.1).
Searched in the following locations:
<https://jcenter.bintray.com/io/ktor/ktor-client-core/1.4.1/ktor-client-core-1.4.1.jar>
not sure if there's issue with some mirror....can open https://jcenter.bintray.com/io/ktor/ktor-client-core/1.4.1/ in a browser and I see that file....anyone else seeing this?robnik
09/27/2020, 1:26 AMAndrew Gazelka
09/27/2020, 4:38 PMSam Garfinkel
09/27/2020, 6:36 PMktor-network
as a commonMain dependency doesn’t work? I was under the impression newer versions of KMP projects allowed declaring a single common artifact and all compatible platforms in the project would automatically add their platform-dependent artifact too.Patrick
09/28/2020, 12:31 PMJoost Klitsie
09/28/2020, 1:47 PMimport io.ktor.client.features.json.serializer.*
//....
install(JsonFeature) {
serializer = KotlinxSerializer(json)
}
Does anyone know where it went?Patrick
09/28/2020, 2:55 PMplugins {
kotlin("jvm") version "1.4.10"
kotlin("plugin.serialization") version "1.4.10"
java
`maven-publish`
}
group = "com.test"
version = "1.0-beta"
val ktorVersion = "1.4.1"
val logbackVersion = "1.2.3"
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
implementation("io.ktor:ktor-server-core:$ktorVersion")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-serialization:$ktorVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0-RC2")
}
And this is my configuration:
install(ContentNegotiation) {
json(Json {
isLenient = true
})
}
install(StatusPages) {
exception<Throwable> { e ->
call.respond(HttpStatusCode.InternalServerError, mapOf("OK" to false, "error" to e.message))
}
}
This compiles, but when I try to start the server I get this error:
Exception in thread "Thread-0" java.lang.NoSuchMethodError: 'kotlinx.serialization.json.Json kotlinx.serialization.json.JsonKt.Json$default(kotlinx.serialization.json.Json, kotlin.jvm.functions.Function1, int, java.lang.Object)'
at io.ktor.serialization.JsonSupportKt.<clinit>(JsonSupport.kt:29)
Is this a common error? What should I change?Andrew Gazelka
09/28/2020, 3:35 PMKris Wong
09/28/2020, 8:28 PMSlackbot
09/28/2020, 8:28 PMRui
09/29/2020, 2:37 PMcall.receive<Parameters>()
and got:
Unable to invoke no-args constructor for interface io.ktor.http.Parameters. Registering an InstanceCreator with Gson for this type may fix this problem
Any ideas?Marcin Bak
09/29/2020, 6:25 PMJohn O'Reilly
09/29/2020, 8:00 PMJohn O'Reilly
09/29/2020, 8:00 PMrusshwolf
09/29/2020, 8:39 PM1.3.9-native-mt
instead of 1.3.9-native-mt-2
John O'Reilly
09/29/2020, 8:40 PMisForce = true
on the kotlinx-coroutines dependencyrusshwolf
09/29/2020, 8:43 PM./gradlew dependencies
anyway and see if there's anything surprisingJohn O'Reilly
09/29/2020, 8:45 PMmt-2
e.g. for sqldelight
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.3.9-native-mt-2
ensureNeverFrozen()
in my project that it's using but then get different crashrusshwolf
09/30/2020, 1:27 PMJohn O'Reilly
09/30/2020, 1:29 PMeopleInSpaceApi@2f31fb8 has failed, first blocker is com.surrus.common.remote.PeopleInSpaceApi
which I guess is point that ktor client request is being madekotlin.native.concurrent.FreezingException: freezing of <no name provided>_1@3b81ce8 has failed, first blocker is com.surrus.common.remote.PeopleInSpaceApi@35c88a8
at 0 PeopleInSpaceSwiftUI 0x000000010d3ceccd kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93
at 1 PeopleInSpaceSwiftUI 0x000000010d3c787b kfun:kotlin.Exception#<init>(kotlin.String?){} + 91
at 2 PeopleInSpaceSwiftUI 0x000000010d3c7acb kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91
at 3 PeopleInSpaceSwiftUI 0x000000010d3fd8f3 kfun:kotlin.native.concurrent.FreezingException#<init>(kotlin.Any;kotlin.Any){} + 643
at 4 PeopleInSpaceSwiftUI 0x000000010d3fef77 ThrowFreezingException + 231
at 5 PeopleInSpaceSwiftUI 0x000000010d4ee10f FreezeSubgraph + 2815
at 6 PeopleInSpaceSwiftUI 0x000000010d50733b Kotlin_Worker_freezeInternal + 27
at 7 PeopleInSpaceSwiftUI 0x000000010d3fda1e kfun:kotlin.native.concurrent#freeze@0:0(){0§<kotlin.Any?>}0:0 + 62
at 8 PeopleInSpaceSwiftUI 0x000000010d758df2 kfun:io.ktor.util.collections.internal.MapNode.<no name provided>_1.<init>#internal.33 + 338
at 9 PeopleInSpaceSwiftUI 0x000000010d75776d kfun:io.ktor.util.collections.internal.MapNode#<init>(1:0;1:1){} + 701
at 10 PeopleInSpaceSwiftUI 0x000000010d748461 kfun:io.ktor.util.collections.ConcurrentMap.put$lambda-3#internal + 1137
at 11 PeopleInSpaceSwiftUI 0x000000010d74c935 kfun:io.ktor.util.collections.ConcurrentMap.$put$lambda-3$FUNCTION_REFERENCE$25.invoke#internal + 165
at 12 PeopleInSpaceSwiftUI 0x000000010d7473d7 kfun:io.ktor.util.collections.ConcurrentMap.locked#internal + 439
at 13 PeopleInSpaceSwiftUI 0x000000010d745adb kfun:io.ktor.util.collections.ConcurrentMap#put(1:0;1:1){}1:1? + 379
at 14 PeopleInSpaceSwiftUI 0x000000010d7ce6e1 kfun:io.ktor.client.HttpClientConfig#install(io.ktor.client.features.HttpClientFeature<0:0,0:1>;kotlin.Function1<0:0,kotlin.Unit>){0§<kotlin.Any>;1§<kotlin.Any>} + 1041
at 15 PeopleInSpaceSwiftUI 0x000000010d32ac62 kfun:com.surrus.common.remote.PeopleInSpaceApi.<init>$lambda-4$lambda-3#internal + 386
at 16 PeopleInSpaceSwiftUI 0x000000010d32b59f kfun:com.surrus.common.remote.PeopleInSpaceApi.$<init>$lambda-4$lambda-3$FUNCTION_REFERENCE$16.invoke#internal + 95
at 17 PeopleInSpaceSwiftUI 0x000000010d32b61f kfun:com.surrus.common.remote.PeopleInSpaceApi.$<init>$lambda-4$lambda-3$FUNCTION_REFERENCE$16.$<bridge-UNNN>invoke(-1:0){}#internal + 95
at 18 PeopleInSpaceSwiftUI 0x000000010d7c8013 kfun:io.ktor.client#HttpClient(io.ktor.client.engine.HttpClientEngineFactory<0:0>;kotlin.Function1<io.ktor.client.HttpClientConfig<0:0>,kotlin.Unit>){0§<io.ktor.client.engine.HttpClientEngineConfig>}io.ktor.client.HttpClient + 595
at 19 PeopleInSpaceSwiftUI 0x000000010d81ae1e kfun:io.ktor.client#HttpClient(kotlin.Function1<io.ktor.client.HttpClientConfig<*>,kotlin.Unit>){}io.ktor.client.HttpClient + 638
at 20 PeopleInSpaceSwiftUI 0x000000010d32ae7f kfun:com.surrus.common.remote.PeopleInSpaceApi.<init>$lambda-4#internal + 223
at 21 PeopleInSpaceSwiftUI 0x000000010d32b15d kfun:com.surrus.common.remote.PeopleInSpaceApi.$<init>$lambda-4$FUNCTION_REFERENCE$13.invoke#internal + 157
at 22 PeopleInSpaceSwiftUI 0x000000010d3ffe15 kfun:kotlin.native.concurrent.FreezeAwareLazyImpl.getOrInit#internal + 1045
at 23 PeopleInSpaceSwiftUI 0x000000010d4005ae kfun:kotlin.native.concurrent.FreezeAwareLazyImpl#<get-value>(){}1:0 + 670
at 24 PeopleInSpaceSwiftUI 0x000000010d3254a3 kfun:com.surrus.common.remote.PeopleInSpaceApi.<get-client>#internal + 323
at 25 PeopleInSpaceSwiftUI 0x000000010d3261d7 kfun:com.surrus.common.remote.PeopleInSpaceApi.$fetchPeopleCOROUTINE$0#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any? + 2983
at 26 PeopleInSpaceSwiftUI 0x000000010d327d94 kfun:com.surrus.common.remote.PeopleInSpaceApi#fetchPeople(){}com.surrus.common.remote.AstroResult + 244
at 27 PeopleInSpaceSwiftUI 0x000000010d32e186 kfun:com.surrus.common.repository.PeopleInSpaceRepository.$fetchPeople$lambda-1COROUTINE$5.invokeSuspend#internal + 726
at 28 PeopleInSpaceSwiftUI 0x000000010d3f07f6 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 758
at 29 PeopleInSpaceSwiftUI 0x000000010d5bba52 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2802
louiscad
09/30/2020, 1:58 PMribesg
09/30/2020, 1:59 PMJohn O'Reilly
09/30/2020, 2:00 PMInvalidMutabilityException
) (with "Frozen during lazy computation" message)public actual fun <T> lazy(initializer: () -> T): Lazy<T> = FreezeAwareLazyImpl(initializer)
private val client by lazy {
HttpClient() {
InstanceCreationException: Could not create instance for [Single:'com.surrus.common.remote.PeopleInSpaceApi
) seems in turn to be related to another
InvalidMutabilityException: mutation attempt of frozen com.surrus.common.remote.PeopleInSpaceApi@
russhwolf
09/30/2020, 3:45 PMJohn O'Reilly
09/30/2020, 3:46 PMHttpClient
to not use by lazy
(but again KaMPKit is also doing that so not sure yet what difference is)by lazy
means that the HttpClient
instance is being created when PeopleInSpaceApi
is created ....triggering mutation attempt of frozen com.surrus.common.remote.PeopleInSpaceApi
breedModel = BreedModel()
in NativeViewModel
....and BreedModel
then uses Koin to inject dependencies (like KtorApi
)Ktor
issue 🙂 )russhwolf
09/30/2020, 4:41 PMJohn O'Reilly
09/30/2020, 5:39 PMlouiscad
09/30/2020, 5:40 PMJohn O'Reilly
09/30/2020, 5:40 PMHttpClient
for 1.4.1 release https://github.com/ktorio/ktor/commit/3471ee7e00a0fdf09375d9d16617d5540cc02a9a#diff-cac393be67723a02e3a8cc96c0f298a5nrobi
11/07/2020, 8:51 PMJohn O'Reilly
11/07/2020, 8:52 PMribesg
11/08/2020, 4:18 PMnrobi
11/08/2020, 4:53 PMIncorrectDereferenceException: illegal attempt to access non-shared object from other thread
, which makes sense and was fixed by explicitly freezing the KtorApi
Then I was hitting InvalidMutabilityException
, converted the KtorApi
to an object and made it @ThreadLocal
, but the InvalidMutabilityException
still occured.
• The IncorrectDereferenceException should be fixed by: https://github.com/ktorio/ktor/pull/2092, with the new release
• I still don’t quite get, why KtorApi
needs to be explicitly frozen, if it’s an object
• If I’m correct even if @ThreadLocal
introduces side-effects/new issues, it should’ve fixed InvalidMutabilityException
ribesg
11/09/2020, 11:29 AM