Using Ktor results in CallNotFoundException due to work on wrong thread
還沒有人認領這個 Issue。
評估
研究方向
報告在 withContext(Dispatchers.IO) 中重現了 PlacesApi.placeAutocomplete(...).await(),並在堆疊追蹤中指向 GaePendingResult.await。首先重現 Ktor/App Engine 請求,並追蹤協程調度器如何與函式庫的請求處理互動。確認與執行緒相關的失敗,且 repository 中有受支援的修正或明確記錄的相容性指南後,即可視為完成。
由索引模型根據 Issue 內容生成。
描述
I'm using Ktor, which is based on coroutines. This seems to be conflicting with the thread manager that the Google Maps Platform Java library uses. It keeps giving me an Unexpected exception from com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call urlfetch.Fetch in a thread that is neither the original request thread nor a thread created by ThreadManager error.
Environment details
- Specify the API at the beginning of the title (for example, "Places: ...")
- OS type and version
- Library version and other environment information
Places Autocomplete
Kotlin 1.4
0.11.0
Steps to reproduce
- Make a request to
PlacesApi.placeAutocomplete(context, query, null).await()
Code example
fun Application.placesAutocomplete() {
routing {
get("/v1/places/autocomplete") {
val parameters = call.request.queryParameters
val query: String? = parameters["query"]
val type: String? = parameters["type"]
if (query == null) {
call.respondParameterRequired("query")
return@get
}
if (query.isBlank()) {
call.respond(AutocompleteResponse(emptyList()))
return@get
}
val PLACES_KEY = System.getenv("PLACES_KEY")
val placeAutocompleteTypes = try {
type?.let { PlaceAutocompleteType.valueOf(type) }
} catch (e: IllegalArgumentException) {
call.respond(HttpStatusCode.BadRequest, "Invalid place type")
return@get
}
val context = GeoApiContext.Builder(GaeRequestHandler.Builder()).apiKey(PLACES_KEY).build()
val placeAutocompleteRequest = PlacesApi.placeAutocomplete(context, query, null)
placeAutocompleteTypes?.let { types ->
placeAutocompleteRequest.types(types)
}
try {
val placeAutocompleteResponse = withContext(Dispatchers.IO) { placeAutocompleteRequest.await() }
val places = placeAutocompleteResponse.map {
val formatting = it.structuredFormatting
Place(
placeId = it.placeId, mainText = formatting.mainText
?: "", secondaryText = formatting.secondaryText
?: ""
)
}
val autocompleteResponse = AutocompleteResponse(places)
call.respond(autocompleteResponse)
} catch (e: Exception) {
call.respond(HttpStatusCode.InternalServerError, e)
}
}
}
}
Stack trace
com.google.maps.errors.UnknownErrorException: Unexpected exception from com.google.apphosting.api.ApiProxy$CallNotFoundException: Can't make API call urlfetch.Fetch in a thread that is neither the original request thread nor a thread created by ThreadManager
at com.google.maps.internal.GaePendingResult.await(GaePendingResult.java:121)
at com.google.maps.PendingResultBase.await(PendingResultBase.java:58)
at appengine.PlacesAutocompleteKt$placesAutocomplete$1$1$placeAutocompleteResponse$1.invokeSuspend(PlacesAutocomplete.kt:74)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:272)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:79)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at appengine.PlacesAutocompleteKt$placesAutocomplete$1$1.invokeSuspend(PlacesAutocomplete.kt:74)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:175)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:137)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:108)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:307)
at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:317)
at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:249)
at retrofit2.KotlinExtensions$awaitResponse$2$2.onResponse(KotlinExtensions.kt:93)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:129)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
- 主要語言
- Java
- 星號
- 1.8k
- 分支
- 972
- 平均合併
- 5 小時 7 分鐘
- 30 天內合併 PR
- 1
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
googlemaps/google-maps-services-java 的其他 Issue
-
PlacesApi.placeDetails(context, placeId).await() interface error可能已有人在做 @madtriceps 於 99 天前認領。 未關閉triage me type: bug
難度 3/5 1-2 天 新手友好度 48/100
-
triage me type: feature request
難度 5/5 一週以上 新手友好度 10/100
-
Bagg hacm未關閉
難度 5/5 一週以上 新手友好度 5/100
googlemaps/google-maps-services-java#1059 · 1 個 reaction ·
-
Issue in java da未關閉
難度 5/5 一週以上 新手友好度 10/100
-
Issue in java da未關閉
難度 5/5 一週以上 新手友好度 10/100
查看 googlemaps/google-maps-services-java 的全部 Issue
相似的 Issue
-
Area-UIUX Issue-Bug Issue-Easy (good first issue)
難度 2/5 1-3 小時 新手友好度 67/100
TeamAmaze/AmazeFileManager#4769 ·
維護者通常 7 天內回覆
-
Expose SManga.memo & SChapter.memo fields in GraphQL APIs to support source-specific client features未關閉enhancement
難度 2/5 1-3 小時 新手友好度 72/100
Suwayomi/Suwayomi-Server#2551 ·
維護者通常 9 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
weaviate/java-client#631 ·
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 2 天內回覆