Unexplained `kotlinx.coroutines.JobCancellationException: Job was cancelled` with kotlin coroutines and spring WebClient?

Viewed 4398

I have a bit of code written using kotlin coroutines

suspend fun getData(request: Request): Response {

        return try {
                webClient.post()
                        .uri(path)
                        .body(BodyInserters.fromObject(request))
                        .retrieve()
                        .awaitExchange()
                        .awaitBody<Response>()
        } catch (e: Exception) {
            logger.error("failed", e)
            throw Exception("failed", e)
        }
    }

I am calling this bit of code like

 val response = withContext(Dispatchers.IO) {
   client.getData(request)
}

In my logs i see this exception happening from time to time kotlinx.coroutines.JobCancellationException: Job was cancelled but this does not allow me to find what actually went wrong. I assume one of the suspending extension functions (awaitExchange or awaitBody) failed but i am not sure of that.

0 Answers
Related