Using Ktor results in CallNotFoundException due to work on wrong thread
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 30/100
Rechercherichtung
Der Bericht reproduziert PlacesApi.placeAutocomplete(...).await() innerhalb von withContext(Dispatchers.IO) und verweist im Stacktrace auf GaePendingResult.await. Beginne damit, die Ktor/App Engine-Anfrage zu reproduzieren und nachzuverfolgen, wie der Coroutine-Dispatcher mit der Anfragenverarbeitung der Bibliothek interagiert. Als erledigt gilt die Aufgabe, wenn der threadbezogene Fehler bestätigt ist und das Repository eine unterstützte Behebung oder klar dokumentierte Kompatibilitätshinweise enthält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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)
- Vorherrschende Sprache
- Java
- Sterne
- 1.8k
- Forks
- 972
- Ø Merge
- 5 Std. 7 Min.
- Gemergte PRs (30 T.)
- 1
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus googlemaps/google-maps-services-java
-
PlacesApi.placeDetails(context, placeId).await() interface errorEvtl. vergeben @madtriceps hat das vor 99 Tagen übernommen. Offentriage me type: bug
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
-
[email protected]Offentriage me type: feature request
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 10/100
-
Bagg hacmOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 5/100
googlemaps/google-maps-services-java#1059 · 1 Reaktion ·
-
Issue in java daOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 10/100
-
Issue in java daOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 10/100
Alle Issues in googlemaps/google-maps-services-java
Ähnliche Issues
-
Area-UIUX Issue-Bug Issue-Easy (good first issue)
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
TeamAmaze/AmazeFileManager#4769 ·
Maintainer antworten meist innerhalb von 7 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
open-feature/java-sdk#2076 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Expose SManga.memo & SChapter.memo fields in GraphQL APIs to support source-specific client featuresOffenenhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Suwayomi/Suwayomi-Server#2551 ·
Maintainer antworten meist innerhalb von 9 Tagen
-
CLI: enforce absolute ADB device paths in file and directory commandsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
weaviate/java-client#631 ·