https://kotlinlang.org logo
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
benchmarks
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
confetti
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
hiring-french
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
lincheck
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
Title
a

Amritansh

11/11/2020, 1:32 AM
Uncaught Kotlin exception: kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[MainDispatcher, Continuation @ $postRequest$lambda-1COROUTINE$1]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
    at 0   shared                              0x0000000103e8730c kfun:kotlin.Error#<init>(kotlin.String?;kotlin.Throwable?){} + 124 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:14:63)
    at 1   shared                              0x0000000103ffa913 kfun:kotlinx.coroutines.CoroutinesInternalError#<init>(kotlin.String;kotlin.Throwable){} + 115 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Exceptions.common.kt:28:77)
    at 2   shared                              0x0000000104042bfa kfun:kotlinx.coroutines.DispatchedTask#handleFatalException(kotlin.Throwable?;kotlin.Throwable?){} + 938 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:93:22)
    at 3   shared                              0x00000001040427e8 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 3512 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:64:13)
    at 4   shared                              0x000000010406b0f5 kfun:kotlinx.coroutines.DarwinMainDispatcher.dispatch$lambda-0#internal + 85 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:35:19)
    at 5   shared                              0x000000010406b4ab kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda-0$FUNCTION_REFERENCE$43.invoke#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:34:51)
    at 6   shared                              0x000000010406b50b kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda-0$FUNCTION_REFERENCE$43.$<bridge-UNN>invoke(){}#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:34:51)
    at 7   shared                              0x000000010406c5c4 _6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f7265_knbridge8 + 180 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:34:51)
    at 8   libdispatch.dylib                   0x0000000104983dd4 _dispatch_call_block_and_release + 12
    at 9   libdispatch.dylib                   0x0000000104984d48 _dispatch_client_callout + 8
    at 10  libdispatch.dylib                   0x0000000104992de6 _dispatch_main_queue_callback_4CF + 1500
    at 11  CoreFoundation                      0x00007fff23bd4049 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    at 12  CoreFoundation                      0x00007fff23bceca9 __CFRunLoopRun + 2329
    at 13  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
    at 14  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
    at 15  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
    at 16  iosApp-sample                       0x0000000103b0405b main + 75 (/Users/atripathi/shared/iosApp-sample/iosApp-sample/AppDelegate.swift:4:7)
    at 17  libdyld.dylib                       0x00007fff5227ec25 start + 1
Caused by: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
    at 0   shared                              0x0000000103e8e52d kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
    at 1   shared                              0x0000000103e8741b kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
    at 2   shared                              0x0000000103e875db kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
    at 3   shared                              0x0000000103eba3db kfun:kotlin.native.IncorrectDereferenceException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/Runtime.kt:30:36)
    at 4   shared                              0x0000000103edbb61 ThrowIncorrectDereferenceException + 129 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:103:11)
    at 5   shared                              0x0000000103fc5c89 CheckIsMainThread + 25
    at 6   shared                              0x00000001041a57e3 kfun:io.ktor.http.<get-HeaderFieldValueSeparators>#internal + 19 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-http/common/src/io/ktor/http/HeaderValueWithParameters.kt:10:9)
    at 7   shared                              0x00000001041a6e24 kfun:io.ktor.http.checkNeedEscape#internal + 356 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-http/common/src/io/ktor/http/HeaderValueWithParameters.kt:86:13)
    at 8   shared                              0x00000001041a65d5 kfun:io.ktor.http.HeaderValueWithParameters#toString(){}kotlin.String + 2101 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-http/common/src/io/ktor/http/HeaderValueWithParameters.kt:41:21)
    at 9   shared                              0x00000001041fb0f7 kfun:io.ktor.client.engine#mergeHeaders(io.ktor.http.Headers;io.ktor.http.content.OutgoingContent;kotlin.Function2<kotlin.String,kotlin.String,kotlin.Unit>){} + 3095 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/Utils.kt:45:37)
    at 10  shared                              0x000000010423adfe kfun:io.ktor.client.engine.ios.IosClientEngine.$executeCOROUTINE$0#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any? + 5630 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosClientEngine.kt:40:13)
    at 11  shared                              0x000000010423c2a4 kfun:io.ktor.client.engine.ios.IosClientEngine#execute(io.ktor.client.request.HttpRequestData){}io.ktor.client.request.HttpResponseData + 308 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosClientEngine.kt:21:22)
    at 12  shared                              0x00000001041f813b kfun:io.ktor.client.engine.HttpClientEngine.$executeWithinCallContext$lambda-1COROUTINE$11.invokeSuspend#internal + 731 (/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/engine/HttpClientEngine.kt:86:13)
    at 13  shared                              0x0000000103eafc16 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 758 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:30:39)
    at 14  shared                              0x00000001040424ff kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2767 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/DispatchedTask.kt:39:50)
    at 15  shared                              0x0000000103ff5ecf kfun:kotlinx.coroutines.EventLoopImplBase#processNextEvent(){}kotlin.Long + 799 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/EventLoop.common.kt:274:18)
    at 16  shared                              0x000000010405a228 kfun:kotlinx.coroutines#runEventLoop(kotlinx.coroutines.EventLoop?;kotlin.Function0<kotlin.Boolean>){} + 872 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Builders.kt:80:40)
    at 17  shared                              0x0000000104062b85 kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.start$lambda-0#internal + 389 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:49:17)
    at 18  shared                              0x0000000104062d5b kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.invoke#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
    at 19  shared                              0x0000000104062dbb kfun:kotlinx.coroutines.WorkerCoroutineDispatcherImpl.$start$lambda-0$FUNCTION_REFERENCE$35.$<bridge-UNN>invoke(){}#internal + 59 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Workers.kt:47:24)
    at 20  shared                              0x0000000103ebdfe7 WorkerLaunchpad + 183 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:69:54)
    at 21  shared                              0x0000000103fbb09f _ZN6Worker19processQueueElementEb + 3135
    at 22  shared                              0x0000000103fba446 _ZN12_GLOBAL__N_113workerRoutineEPv + 54
    at 23  libsystem_pthread.dylib             0x00007fff524602eb _pthread_body + 126
    at 24  libsystem_pthread.dylib             0x00007fff52463249 _pthread_start + 66
    at 25  libsystem_pthread.dylib             0x00007fff5245f40d thread_start + 13
(lldb)
This is what my implementation looks like
fun postRequest() {
        MainScope().launch {
            withContext(Dispatchers.Default) {
                 HttpClient().post("URL"){
                   body = "some json"
                 }
            }
        }
    }
This request is working fine for the Android application and only throws the exception in iOS. Also if I try to run  HttpClient().post on the main thread, it works fine on iOS and I am successfully able to send the request. ktorVersion = "1.4.2" coroutinesVersion = "1.3.9-native-mt-2"
j

John O'Reilly

11/11/2020, 8:03 AM
in repo where we were seeing this (https://github.com/joreilly/PeopleInSpace/issues/11), I had to revert back to Ktor 1.4.0 for now
e

e5l

11/11/2020, 4:51 PM
@Vsevolod Tolstopyatov [JB]
t

Thomas

11/11/2020, 6:13 PM
It was caused by another commit that added a top level value not marked as
@SharedImmutable
.
@e5l
e

e5l

11/11/2020, 7:10 PM
Thanks, will merge before
1.4.3
👍 2
a

Amritansh

11/11/2020, 8:09 PM
@Thomas Thanks for opening a pr for this issue. I just ran a build on your ktor fork to import it manually. I need jar files for iOS android and common main, can you tell me which jar files I should use? There are many generated jar files and I not sure which one to use
t

Thomas

11/11/2020, 8:31 PM
@Amritansh First run a gradle build on the Ktor project. Then run the publishToMavenLocal task. Then add Ktor to your application as version “1.4.3-SNAPSHOT”. Make sure to add
mavenLocal()
to your project as well (above all other repositories)
a

Amritansh

11/11/2020, 9:59 PM
@Thomas Testcases are failing when I am running the build
io.ktor.tests.server.jetty.http2.JettyHttp2AsyncServletContainerSustainabilityTest[jvm] > testBigFile[jvm] FAILED
    org.junit.runners.model.TestTimedOutException at Unsafe.java:-2

io.ktor.client.tests.MultithreadedTest[jvm] > numberTest[OkHttp][jvm] FAILED
    org.junit.runners.model.TestTimedOutException at MultithreadedTest.kt:19
I am on this branch
fix_incorrectdereferenceexception
Exception in thread "main" java.lang.Error: /var/folders/pc/f99yxpjj3tg1pwzdyx8jlwxcsjs57v/T/tmp8949358749675910999.c:1:10: fatal error: 'curl.h' file not found
        at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
        at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.indexDeclarations(Indexer.kt:1003)
        at org.jetbrains.kotlin.native.interop.indexer.IndexerKt.buildNativeIndexImpl(Indexer.kt:992)
        at org.jetbrains.kotlin.native.interop.indexer.NativeIndexKt.buildNativeIndex(NativeIndex.kt:91)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:266)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:72)
        at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
        at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
        at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:37)

> Task :ktor-client:ktor-client-curl:cinteropLibcurlMacosX64 FAILED
t

Thomas

11/11/2020, 10:21 PM
You probably don't have curl installed, that is required for the tests
You could just add
@Ignore
to every test that is failing, that should work I think
a

Amritansh

11/11/2020, 11:16 PM
@Thomas Curl was the issue. I just tested this in my project and your fix works. No more exception on iOS. Thanks for the help man!
🎉 1