https://kotlinlang.org logo
Docs
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
  • r

    rsetkus

    10/24/2020, 7:36 PM
    Hi. Developing multiplatform library for Android and iOS. At the moment don't need anything specific for Android so targeting jvm and iOS. Getting an error on Android application when making a Ktor request call. By the way, I don't get a such error on unit test at commonMain module which runs against jvm. Any ideas what can cause this error?
    io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteChannelKt$ByteChannel$1 (Kotlin reflection is not available) -> class xxx.YYY (Kotlin reflection is not available)
        with response from <https://XXX>:
        status: 200 OK
        response headers: 
        cache-control: max-age=600
        , connection: keep-alive
        , content-type: application/json;charset=utf-8
        
            at io.ktor.client.call.HttpClientCall.receive(HttpClientCall.kt:84)
    l
    9 replies · 2 participants
  • u

    ursus

    10/24/2020, 11:48 PM
    Hi, with ktor client, is there a equivalent of okhttp interceptors or authenticator?
    👀 1
    r
    l
    +2
    9 replies · 5 participants
  • h

    Hyun

    10/25/2020, 4:31 PM
    Hi everyone, I need some advice from Ktor developers. I created a KMP library targeting backend, android, ios - To share api interface between server and client. - Without Http definition like GET, POST, Body, Query etc.. (so, it’s totally looks same with just ‘function’) will this be fine approach? or some advice for this approach? common
    @Api
    interface SampleApi {
        suspend fun getGreeting(name: String, job: String): String
    }
    client
    inline fun <reified API> api(baseUrl: String = serverUrl): API = client.create(baseUrl)
    
    scope.launch {
        api<SampleApi>().getGreeting("Hyun", "Programmer")
    }
    backend
    class SampleController : SampleApi {
        override suspend fun getGreeting(name: String, job: String): String = "Hello $name($job)"
    }
    
    install(SimpleFeature) {
        routing {
            +SampleController()
        }
    }
    1 reply · 1 participant
  • s

    Sourabh Rawat

    10/26/2020, 10:57 AM
    This does not seem to work and is throwing
    Serializer for class 'ApiResponse' is not found
    @Serializable
    data class ApiResponse<T>(
        val result: T? = null,
        val error: ApiError? = null
    )
    call.respond(ApiResponse(result = gameEngine.newGame()))
    Please help. Json.encodeToString(..) works fine. ktor config:
    fun Application.mainModule() {
    
      install(ContentNegotiation) {
        json()
      }
      ...
    }
    Using ktor 1.4.1 and serialization 1.0.0
    a
    c
    +1
    14 replies · 4 participants
  • r

    rnett

    10/27/2020, 1:04 AM
    I've seen it mentioned in a few places that a kotlin native server is in the works (eventually). I assume you're going to have to write a HOCON parser for it, are there any plans to open source a multiplatform HOCON parser (and hopefully a kotlinx.serialization backend)?
    ❤️ 1
    c
    s
    6 replies · 3 participants
  • n

    napperley

    10/27/2020, 3:34 AM
    Keep on getting a segmentation fault when creating an instance of
    HttpClient
    using this project: https://gitlab.com/napperley/openfaas-weather-sample
    c
    e
    6 replies · 3 participants
  • a

    aleksey.tomin

    10/27/2020, 5:10 AM
    How can I use gzip for ktor-client POST requests (not response)? ktolin 1.4.10, ktor 1.4.1, native/curl I’ve added
    ContentEncoding {
                gzip()
            }
    But the server team says that request body not in gzip.
    a
    4 replies · 2 participants
  • d

    Dario Pellegrini

    10/27/2020, 1:19 PM
    Hello everyone! Is there a way in Ktor to detect whenever a reques is canceled by the client? I have a long running process which could be canceled and I’d like to release some file resources it uses on client request’s cancellation. Can someone help me in doing this?
    j
    2 replies · 2 participants
  • n

    Nikky

    10/27/2020, 3:49 PM
    i am getting
    Fail to fetch
    in browser tests to localhost seems to be somehow
    Access-Control-Allow-Origin
    related
    can i ignore this or force the browser to ignore this with ktor-client ?
    r
    1 reply · 2 participants
  • a

    Andrew Gazelka

    10/28/2020, 12:54 AM
    does ktor modify the URL sent into
    client.get(url: String)
    ? because I am getting an Http error with ktor and no error with curl and I am really confused
    1 reply · 1 participant
  • j

    Joaquim Ley

    10/28/2020, 2:55 PM
    kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 82: Expected string literal with quotes.
    c
    4 replies · 2 participants
  • c

    Carlos Fau

    10/28/2020, 9:48 PM
    Hi, we're trying to configure JSON in KTOR Server using kotlinx. We have Ktor 1.4.1, the documentations says to use the function
    serialization()
    but we can't find it in packages. Any help?
    h
    3 replies · 2 participants
  • t

    turansky

    10/30/2020, 1:45 PM
    Is there common practice for
    HttpClient
    (JS client) ? Do I need single
    HttpClient
    if I have single API source?
    GET /api/a
    GET /api/b
    GET /api/c
    GET /api/d
    a
    1 reply · 2 participants
  • e

    Elka

    11/02/2020, 5:52 PM
    Hello, Using the Ktor HttpClient on Android and iOS. I need to do some kind of json validation for authorization purposes… I am trying to create a
    Feature
    that parses the json, does the checking and then proceed with the response… The problem is that I cannot call
    readBytes
    twice. The second time it’s empty as the response has already been consumed when doing the validation. Is there any way to do it?
    d
    2 replies · 2 participants
  • j

    John O'Reilly

    11/03/2020, 8:12 AM
    I have Ktor server with following CORS feature installed....works for "normal" requests but not for some reason for digest auth based login request
    install(CORS) {
        anyHost()
        header("Authorization")
    }
    anyone aware of any other config needed to support that?
    j
    a
    8 replies · 3 participants
  • k

    Krystian Rybarczyk

    11/04/2020, 2:42 PM
    hey guys, I’ve found this sample for structured logging: https://github.com/ktorio/ktor-samples/blob/1.3.0/other/structured-logging/src/Application.kt but it’s not quite clear to me how I would use this logger inside other classes (say my service class) so that I can see all other log messages in the context of a particular requestId. Could anyone help?
    👀 1
    d
    7 replies · 2 participants
  • d

    Denis Ambatenne

    11/06/2020, 10:35 AM
    Vote on kTor plugin improvеments 🖖 Hi all! I am working on my version of the kTor plugin and thinking about the functions to cover. After researching several discussions and conduction interviews I came up with a list of features for the new plugin. Please vote by clicking on the relevant emoji. Thanks!!! Project creation 🥐 - Automatically pick features, upon which your chosen feature depends 🥖 - A More concise grouping of feature, like in Spring or Vertx (wed, data access, messaging e.t.c) 🥨 - Ability to choose between plain (currently via kTor plugin) or hierarchical (classical, that you get using Gradle) structure of the src/resources folders 🥞 - Ability to create an example project with recommended architecture for Restful service 🧀 - Ability to create an example project with recommended architecture for DB interaction 🍖 - Ability to create an example project with recommended architecture for event messaging 🍔 - Create a project with the support of different environments: dev, test, production, and custom 🍕 - Create a template project for the creation of a new kTor feature Development/Debugging 🌋 - UI with a list of all current routes (including nested ones) in the current project Testing 🐵 - Endpoint test results visualization Deployment ⚽- convenient way to configure deployment to Google ⚾ - convenient way to configure deployment to Azure 🏀 - convenient way to configure deployment to AWS 🏐- convenient way to configure deployment to Heroku 🏈 - convenient way to configure deployment to Jenkins CI/CD 🎾- convenient way to configure deployment to Travis CI/CD Documentation 🎷 - Swagger API generation and hosting Refactoring 🚒- UI to change the features used (and all the dependencies) in an existing project 🚕- List of unused features And of course, you can add any not listed feature in replies to this post :)
    🚕 5
    🥞 7
    🚒 6
    🏀 4
    🍔 12
    🥖 5
    🍕 4
    ⚾ 3
    🥐 3
    🎾 3
    🌋 19
    🥨 4
    🏐 4
    🍖 6
    ⚽ 5
    🐵 9
    🧀 7
    🎷 27
    🏈 3
    s
    m
    +2
    5 replies · 5 participants
  • m

    Moses Mugisha

    11/06/2020, 7:51 PM
    How do I set
    HttpClient.setMaxRequestsQueuedPerDestination()
    for the jetty engine in ktor?
    1 reply · 1 participant
  • n

    nrobi

    11/08/2020, 2:57 PM
    Anyone experiencing this issue on K/N?
    HttpClient: REQUEST https://... failed with exception: kotlinx.coroutines.CancellationException: Engine failed
    Seems to be tied to
    async
    -
    await
    as it works as expected with
    launch
    a
    3 replies · 2 participants
  • s

    subashz

    11/09/2020, 12:32 PM
    How to enable cache-options in ktor's HttpClient ?
    g
    c
    +1
    4 replies · 4 participants
  • h

    hhariri

    11/10/2020, 3:34 PM
    Ktor 1.4.2 Released Please see [Change Log] for more details!
    🎉 14
    🙏 4
    :party-parrot: 5
    :ktor: 27
    👍 12
    t
    1 reply · 2 participants
  • o

    octylFractal

    11/10/2020, 10:37 PM
    it seems like the 1.4.2 release broke
    call.receive()
    with the jackson content negotiator, I get https://gist.github.com/octylFractal/f973cee5acd96ca757c7b6a83936800f
    1 reply · 1 participant
  • 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
    e
    +1
    15 replies · 4 participants
  • d

    dm6801

    11/11/2020, 6:51 PM
    Getting an exception when trying to use Session feature (cookies) combined with SSL Caused by: java.lang.UnsupportedOperationException: null at io.ktor.server.netty.http2.NettyHttp2ApplicationRequest.getCookies(NettyHttp2ApplicationRequest.kt:64) at io.ktor.sessions.SessionTransportCookie.receive(SessionTransportCookie.kt:28) at io.ktor.sessions.SessionsKt.receiveSessionData(Sessions.kt:204) at io.ktor.sessions.Sessions$Feature$install$1.invokeSuspend(Sessions.kt:59) NettyHttp2ApplicationRequest:64:
    override val cookies: RequestCookies
        get() = throw UnsupportedOperationException()
    working as intended or should I open a youtrack bug?
    1 reply · 1 participant
  • g

    goto1134

    11/11/2020, 7:19 PM
    Are there any plans or milestones to support OAuth token refreshing?
    h
    2 replies · 2 participants
  • r

    Robert Jaros

    11/11/2020, 9:46 PM
    I'm getting this runtime error after migrating to from 1.4.1 to 1.4.2:
    java.lang.IllegalStateException: Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(<http://Dispatchers.IO|Dispatchers.IO>) instead.
    It looks like it has something to do with Jackson. Is this a known issue?
    w
    3 replies · 2 participants
  • a

    Archie

    11/12/2020, 8:42 AM
    Hi have anyone work with making Ktor Client and Coil-Kt work together? I need to configure Ktor and Coil to use the same configuration, (Default Request, Interceptor, Auth, etc. etc.) But
    Ktor
    require
    HttpClientEngine
    but
    Coil
    needs the
    OkHttpClient
    itself. Is there a way to make both work together?
    r
    2 replies · 2 participants
  • t

    tieskedh

    11/12/2020, 5:45 PM
    I want to create a data-receiver object which has no dependencies on Ktor. That's why I translated the ByteReadChannel to a Flow using common-Kotlin. I don't have much experience in this area, so my question is: Is this method safe and is it the best way?
    suspend inline fun ByteReadChannel.toFlow(): Flow<ByteArray> {
        return flow {
            do {
                read { source, start, endExclusive ->
                    val array = when {
                        endExclusive > start -> {
                            val mem = source.slice(start, endExclusive - start)
                            val byteArray = ByteArray(mem.size.toInt())
                            mem.copyTo(byteArray, 0, mem.size.toInt())
                            byteArray
                        }
                        else -> byteArrayOf()
                    }
    
                    emit(array)
                    255
                }
                if (isClosedForRead) break
            } while (currentCoroutineContext().isActive)
        }
    }
    r
    2 replies · 2 participants
  • a

    Alberto Quario

    11/13/2020, 4:52 PM
    Hi, I have added metrics to an application like this:
    install(MicrometerMetrics) {
            registry = DatadogMeterRegistry(config, Clock.SYSTEM)
            ...
        }
    Would it be possible to access and reuse the same registry for adding custom metrics in handlers? Thanks!
    d
    3 replies · 2 participants
  • r

    Rob Hurkes

    11/13/2020, 7:41 PM
    Hey all! Anyone come across this issue with ktor 1.4+ yet? Using Jackson content negotiation, JSON response objects greater than 4kb in size throw an exception
    Exception in thread "eventLoopGroupProxy-3-6" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[UnsafeBlockingTrampoline@762b17ae, Continuation at <http://io.ktor.utils.io|io.ktor.utils.io>.jvm.javaio.OutputAdapter$loop$1.loop(Blocking.kt:311)@64588a54]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
    . The actual cause is further down the stack trace:
    Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation and kotlinx.coroutines.DispatchedContinuation are in unnamed module of loader 'app')
    	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:103)
    I've got a minimal reproduction example up at https://github.com/rhurkes/ktor-playground/commit/989b512bd7209735fd4d223b839d20d307c533c3
    4 replies · 1 participant
Powered by Linen
Title
r

Rob Hurkes

11/13/2020, 7:41 PM
Hey all! Anyone come across this issue with ktor 1.4+ yet? Using Jackson content negotiation, JSON response objects greater than 4kb in size throw an exception
Exception in thread "eventLoopGroupProxy-3-6" kotlinx.coroutines.CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation[UnsafeBlockingTrampoline@762b17ae, Continuation at <http://io.ktor.utils.io|io.ktor.utils.io>.jvm.javaio.OutputAdapter$loop$1.loop(Blocking.kt:311)@64588a54]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers
. The actual cause is further down the stack trace:
Caused by: java.lang.ClassCastException: class kotlin.coroutines.jvm.internal.CompletedContinuation cannot be cast to class kotlinx.coroutines.DispatchedContinuation (kotlin.coroutines.jvm.internal.CompletedContinuation and kotlinx.coroutines.DispatchedContinuation are in unnamed module of loader 'app')
	at kotlinx.coroutines.CoroutineDispatcher.releaseInterceptedContinuation(CoroutineDispatcher.kt:103)
I've got a minimal reproduction example up at https://github.com/rhurkes/ktor-playground/commit/989b512bd7209735fd4d223b839d20d307c533c3
It's similar to some other issues I've seen, but I'm not using coroutines in my app code at all, and the reproduction is rather simple. I don't mind filing a youtrack ticket for this, but wanted to check here first.
Appears to be related to this commit from 1.4.2: https://github.com/ktorio/ktor/commit/0dfada8cd8e438d724ce77e9cd0d8b09a6b8c6dc#diff-9004ca70aa325dbcfa7d3ce09d193306f9f33bfd9c7c7732875f008e294feb6d For some reason larger responses that go through
ContentNegotiation
are ending up tying to
park()
with
ProhibitedParking
which leads to this exception
java.lang.UnsupportedOperationException: Parking is prohibited on this thread. Most likely you are using blocking operation on the wrong thread/dispatcher that doesn't allow blocking. Consider wrapping you blocking code withContext(<http://Dispatchers.IO|Dispatchers.IO>) {...}.
because this work (regardless of size) ends up running through a
withBlocking
here: https://github.com/ktorio/ktor/blob/master/ktor-http/jvm/src/io/ktor/http/content/OutputStreamContent.kt#L23
I'm assuming that exception is what's bringing this
CompletedContinuation
into the mix.
Maybe a missed call to
withBlockingAndRedispatch
? Hard to say, debugging threading issues isn't my bread and butter 😅
View count: 3