https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ktor
  • d

    degreat

    09/19/2020, 2:21 PM
    How do I make this locations match? The first should match alphanumeric, and the second should match integers
    l
    m
    • 3
    • 23
  • a

    aarjav

    09/20/2020, 1:18 AM
    What's the url to ktor 1.3.x docs? everything on https://ktor.io/learn/ points to https://ktor.io/docs/quickstart-index.html which seems to be 1.4 only
    a
    e
    • 3
    • 2
  • j

    John O'Reilly

    09/21/2020, 7:05 AM
    Is it possible, using
    HttpClient
    to apply different types of auths to different requests?
    a
    • 2
    • 15
  • p

    peekandpoke

    09/22/2020, 6:43 AM
    Hi there! Probably this is known already. But the docs are down: https://ktor.io/docs/async.html ... all of them. The link to the github examples are broken as well, which is sad... Where can I find the docs for the 1.3.x versions of Ktor? Thank you!
    j
    • 2
    • 1
  • m

    Mouaad

    09/22/2020, 8:57 AM
    Any news if Ktor will update to kotlinx.serialization RC2 or wait for the stable release?
    l
    c
    • 3
    • 6
  • g

    gotoOla

    09/22/2020, 9:08 AM
    Could anyone explain to me why there are only 5 requests executed in parallel here? (expected 7)
    suspend 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
        }
    }
    g
    • 2
    • 5
  • r

    ribesg

    09/22/2020, 1:19 PM
    @e5l Just saw you just fixed https://youtrack.jetbrains.com/issue/KTOR-973 in master, are dev builds published ? to check if the issue is fixed in my current project and my own (non-minimal) reproducer ? Or maybe I should build it locally ?
    e
    • 2
    • 6
  • b

    bsimmons

    09/22/2020, 2:44 PM
    So I'm on iOS using 1.4.0 and coroutines 1.3.9-native-mt and if I try to make a get request in a
    runBlocking { ... }
    test and it just blocks until the request times out. Any ideas on why this is happening?
    r
    • 2
    • 3
  • r

    ribesg

    09/23/2020, 10:48 AM
    @e5l are they samples/tests/documentation showing how to use the Ktor Client in Native without freezing the coroutine it runs in? This may be the last thing preventing updating
    • 1
    • 2
  • l

    louiscad

    09/23/2020, 12:24 PM
    Isn't the deployment of version 1.4.1 stuck on the Windows runner? https://teamcity.jetbrains.com/buildConfiguration/KotlinTools_Ktor_DeployTrain/3119147?buildTab=dependencies&amp;mode=timeline&amp;state=running&amp;range=1600857393000-1600865914000
    e
    • 2
    • 6
  • c

    Chris Fillmore

    09/23/2020, 6:43 PM
    Fyi JetBrains, quickstart links return 404: https://ktor.io/quickstart/gradle.html
    v
    • 2
    • 1
  • c

    Christian Jensen

    09/24/2020, 5:28 PM
    Struggling a bit with Ktor on iOS with json serialization. I am following the KaMPKit sample, and the only ios dependency is
    implementation("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?
    j
    r
    • 3
    • 3
  • t

    Thomas

    09/24/2020, 6:40 PM
    In the latest Ktor version 1.4.1 I was able to freeze the Ktor client and still make network requests. That is really great, thanks a lot for making this possible. I was wondering if using the
    Ios
    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?
    e
    • 2
    • 12
  • t

    tylerwilson

    09/24/2020, 11:34 PM
    I just tried to update my shared library to Ktor 1.4.1, and updated to serialization 1.0.0-RC2 and coroutines 1.3.9-native-mt-2 (what kind of name is that anyway?), and I am now getting a mutability exception in one our iOS apps that uses it. It works fine with Ktor 1.4.0. I looked at the referenced issues in the release notes, but it sounds like it ought to be more forgiving, not less. Anybody else seeing this?
    e
    • 2
    • 3
  • p

    Pierre Marais

    09/25/2020, 8:02 AM
    Good morning. Are there any Ktor client engines that support TLS1.0? (Apart from Apache). We're having an issue with Apache that threads are using 100% cpu after updating from 1.3.2 to 1.4.0. Will log an issue for this, but as a temporary fix, I'd like to just try a different engine first
    • 1
    • 1
  • v

    Varvara

    09/25/2020, 8:03 AM
    Hi everyone! We’ve released Ktor 1.4.1. For full list of fixes please check out the changelog: https://github.com/ktorio/ktor/blob/master/CHANGELOG.md
    s
    r
    • 3
    • 6
  • o

    Oleg Yukhnevich

    09/25/2020, 9:27 AM
    @e5l Just for curiosity, how stable now TCP Native? Im trying to run tests, which create client and server and communicate. And sometimes it work, and then just stopped sending or receiving data. Or I can't close it, it just block on calling
    Socket.close
    . BTW, what is the best way to close client and server TCP? (seems like order of calling close matters some how)
    e
    • 2
    • 5
  • j

    John O'Reilly

    09/25/2020, 6:53 PM
    I'm getting following when I try to use 1.4.1
    > 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?
    l
    j
    • 3
    • 7
  • r

    robnik

    09/27/2020, 1:26 AM
    Does anyone use Ktor for a web server and update the code without any downtime? I currently have a small digitalocean server, and I use Kotlin + Wildfly. I can update the war and redeploy in a few seconds. I want a way to get that redeploy downtime to zero. I have some websocket connections between the server and apps. Maybe I can swap in a new ktor process while the old one gracefully shuts down its connections.
    👀 1
    s
    • 2
    • 2
  • a

    Andrew Gazelka

    09/27/2020, 4:38 PM
    Is there an idiomatic way using ktor native sockets to send over/receive objects?
    s
    • 2
    • 4
  • s

    Sam Garfinkel

    09/27/2020, 6:36 PM
    Anyone know why using
    ktor-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.
    l
    • 2
    • 1
  • p

    Patrick

    09/28/2020, 12:31 PM
    Is it possible to use kotlinx.serialization with the newest version of ktor server? It seems like the documentation is outdated, since I can't find the serialization() function in kotlinx.serialization. https://ktor.io/docs/serialization-converter.html#configuration
    j
    • 2
    • 26
  • j

    Joost Klitsie

    09/28/2020, 1:47 PM
    However, kotlinxserializer is not found anymore 😞
    import io.ktor.client.features.json.serializer.*
    //....
    
    install(JsonFeature) {
        serializer = KotlinxSerializer(json)
    }
    Does anyone know where it went?
    p
    e
    s
    • 4
    • 27
  • p

    Patrick

    09/28/2020, 2:55 PM
    I am having an issue with kotlinx.serialization 1.0.0-RC2. This is my build.gradle.kts:
    plugins {
        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?
    e
    j
    • 3
    • 6
  • a

    Andrew Gazelka

    09/28/2020, 3:35 PM
    f I send two byte arrays over TCP raw sockets in quick succession, when I read the byte array what I get is the concatenation of both requests. Is there a way to avoid this? (I am flushing)… I am guessing adding a byte specifying the length before sending each byte array would be the best way to solve this?
    e
    • 2
    • 1
  • k

    Kris Wong

    09/28/2020, 8:28 PM
    now that this is fixed: https://youtrack.jetbrains.com/issue/KTOR-973, I am getting this instead: kotlin.native.concurrent.FreezingException
    b
    e
    • 3
    • 12
  • s

    Slackbot

    09/28/2020, 8:28 PM
    This message was deleted.
    b
    • 2
    • 1
  • r

    Rui

    09/29/2020, 2:37 PM
    Hi, I was trying to get parameters from a request body by using
    call.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?
    d
    r
    • 3
    • 5
  • m

    Marcin Bak

    09/29/2020, 6:25 PM
    Is it possible to add a header to a response in Ktor Server? I have several routes and would like to add a header to a specific ones only
    c
    • 2
    • 3
  • j

    John O'Reilly

    09/29/2020, 8:00 PM
    Anyone by chance also run in to following after updating to Ktor 1.4.1? https://youtrack.jetbrains.com/issue/KTOR-1087
    r
    l
    +2
    • 5
    • 41
Powered by Linen
Title
j

John O'Reilly

09/29/2020, 8:00 PM
Anyone by chance also run in to following after updating to Ktor 1.4.1? https://youtrack.jetbrains.com/issue/KTOR-1087
r

russhwolf

09/29/2020, 8:39 PM
I don't hit that despite a very similar setup here https://github.com/russhwolf/multiplatform-hello/blob/master/shared-client/src/commonMain/kotlin/hello.kt
I wonder if sqldelight is causing you to pull in
1.3.9-native-mt
instead of
1.3.9-native-mt-2
j

John O'Reilly

09/29/2020, 8:40 PM
I'm using
isForce = true
on the kotlinx-coroutines dependency
r

russhwolf

09/29/2020, 8:43 PM
Check
./gradlew dependencies
anyway and see if there's anything surprising
j

John O'Reilly

09/29/2020, 8:45 PM
yeah, it's using
mt-2
e.g. for sqldelight
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9 -> 1.3.9-native-mt-2
I updated KaMPKit to 1.4.1 locally and not seeing any issues....I tried making calls to
ensureNeverFrozen()
in my project that it's using but then get different crash
r

russhwolf

09/30/2020, 1:27 PM
That should help diagnose where your freeze is coming from
j

John O'Reilly

09/30/2020, 1:29 PM
it shows
eopleInSpaceApi@2f31fb8 has failed, first blocker is com.surrus.common.remote.PeopleInSpaceApi
which I guess is point that ktor client request is being made
full stack
kotlin.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
looking for differences with KaMPKit.....but at least ktor interaction looks to be much the same
l

louiscad

09/30/2020, 1:58 PM
Looks like something @ribesg encountered.
That depressing "freezing of <no name provided>" 😅
r

ribesg

09/30/2020, 1:59 PM
I’ve encountered them all
😅 1
And I’m far from done.
j

John O'Reilly

09/30/2020, 2:00 PM
this has only started happening for this project after changing from ktor 1.4.0 to 1.4.1 (or perhaps some of the related dependency updates)
I'm still not clear what "freezing of <no name provided>_1@3b81ce8 has failed" is supposed to mean exactly.....is it that ktor did attempt to freeze something (to allow sharing across threads) but it failed (thus leading to original
InvalidMutabilityException
) (with "Frozen during lazy computation" message)
as reported in https://github.com/joreilly/PeopleInSpace/issues/11by (cc @mbonnin )
fwiw this is where that "Frozen during lazy computation" message is coming from https://github.com/JetBrains/kotlin-native/blob/master/runtime/src/main/kotlin/kotlin/native/concurrent/Lazy.kt
and that in turn is used by
public actual fun <T> lazy(initializer: () -> T): Lazy<T> = FreezeAwareLazyImpl(initializer)
and that looks to be difference between PeopleInSpace and KaMPKit....I have following
private val client by lazy {
        HttpClient() {
I'm getting Koin error when I remove use of lazy....looking to fix that (hopefully) and see if that "resolves" the original issue.....but seems like this is bug since those version updates (also updated https://youtrack.jetbrains.com/issue/KTOR-1087)
❤️ 1
the koin error (
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@
r

russhwolf

09/30/2020, 3:45 PM
Are you hitting something Koin-related from a background thread? Koin tries to keep its initialization main-threaded to avoid unexpected freezing.
j

John O'Reilly

09/30/2020, 3:46 PM
I don't believe I am....pretty much using same pattern as used in KaMPKit
but will do closer comparison again and see if I can see any difference
seems to be triggered by changing
HttpClient
to not use
by lazy
(but again KaMPKit is also doing that so not sure yet what difference is)
so, I guess the change to not use
by lazy
means that the
HttpClient
instance is being created when
PeopleInSpaceApi
is created ....triggering
mutation attempt of frozen com.surrus.common.remote.PeopleInSpaceApi
looks like flow is a little different in KaMPKit in that it has
breedModel = BreedModel()
in
NativeViewModel
....and
BreedModel
then uses Koin to inject dependencies (like
KtorApi
)
(anyway, going off topic from original
Ktor
issue 🙂 )
r

russhwolf

09/30/2020, 4:41 PM
I think it's relevant, because it may be an issue of application logic and K/N threading rather than a ktor thing
j

John O'Reilly

09/30/2020, 5:39 PM
I wonder if fact that the repository class is being created in Swift code is a factor
l

louiscad

09/30/2020, 5:40 PM
Can you check it's init on the main thread in Swift code?
j

John O'Reilly

09/30/2020, 5:40 PM
yeah, checked that
looks like a few concurrency related changes made to
HttpClient
for 1.4.1 release https://github.com/ktorio/ktor/commit/3471ee7e00a0fdf09375d9d16617d5540cc02a9a#diff-cac393be67723a02e3a8cc96c0f298a5
jetbrains folks have reproduced issue https://youtrack.jetbrains.com/issue/KTOR-1087
n

nrobi

11/07/2020, 8:51 PM
Facing the same issue, @John O'Reilly did you find out anything more in the last month?
j

John O'Reilly

11/07/2020, 8:52 PM
No, still haven't updated to that version.....that issue still seems to be open
r

ribesg

11/08/2020, 4:18 PM
The Ktor client 1.4+ never worked outside the main thread
👍 1
n

nrobi

11/08/2020, 4:53 PM
Yupp, I was getting first
IncorrectDereferenceException: 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
r

ribesg

11/09/2020, 11:29 AM
Just make your request calls on the main thread.
View count: 9