Firebase Firestore客户端在尝试读取使用Ktor/Java8在App Engine Standard上运行的数据时挂起

Firebase Firestore客户端在尝试读取使用Ktor/Java8在App Engine Standard上运行的数据时挂起,firebase,google-app-engine,kotlin,google-cloud-firestore,ktor,Firebase,Google App Engine,Kotlin,Google Cloud Firestore,Ktor,我在Google应用程序引擎标准环境(使用Java8、Kotlin和Ktor)中与Firestore集成时遇到问题。当我尝试执行任何操作时,Firestore客户端挂起。在dev appserver中运行时,它可以正常工作,但在生产环境中运行时则无法正常工作 我在跑步: Ktor 1.1.2 Kotlin 1.3.21 com.google.cloud:googlecloudfirestore(版本0.81.0-beta) 本机模式下的Firestore 我用这个简单的方法进行了测试: ge

我在Google应用程序引擎标准环境(使用Java8、Kotlin和Ktor)中与Firestore集成时遇到问题。当我尝试执行任何操作时,Firestore客户端挂起。在dev appserver中运行时,它可以正常工作,但在生产环境中运行时则无法正常工作

我在跑步:

  • Ktor 1.1.2
  • Kotlin 1.3.21
  • com.google.cloud:googlecloudfirestore(版本0.81.0-beta)
  • 本机模式下的Firestore
我用这个简单的方法进行了测试:

get("/test") {
    try {
        val firestore = FirestoreOptions.getDefaultInstance().service
        val user = firestore.collection("user").document("testusername").get().get()
        call.respond(user.getString("name")!!)
    } catch (ex: Exception) {
        call.respond("Exception: " + ex)
    }
}
在web浏览器中访问
/test
会导致网站挂起一分钟,然后返回500错误

Google云平台中记录了以下异常:

[e~website/20190306t125554.416577836925362605].<stdout>: 2019-03-06 13:01:31.306 [RequestEDA5B9B5] ERROR Application - Unhandled: GET - /test
java.lang.InterruptedException: null
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:506)
    at com.google.common.util.concurrent.AbstractFuture$TrustedFuture.get(AbstractFuture.java:83)
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:62)
    at com.example.MainApplicationKt$run$4$2.invokeSuspend(MainApplication.kt:93)
    at com.example.MainApplicationKt$run$4$2.invoke(MainApplication.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
    at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:157)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:23)
    at io.ktor.routing.Routing.executeResult(Routing.kt:148)
    at io.ktor.routing.Routing.interceptor(Routing.kt:29)
    at io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:93)
    at io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
    at io.ktor.features.ContentNegotiation$Feature$install$1.invokeSuspend(ContentNegotiation.kt:63)
    at io.ktor.features.ContentNegotiation$Feature$install$1.invoke(ContentNegotiation.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
    at io.ktor.features.CallLogging$Feature$install$2.invokeSuspend(CallLogging.kt:130)
    at io.ktor.features.CallLogging$Feature$install$2.invoke(CallLogging.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
    at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:157)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:23)
    at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:106)
    at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
    at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:278)
    at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
    at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:137)
    at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:157)
    at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:23)
    at io.ktor.server.servlet.KtorServlet$blockingService$1.invokeSuspend(KtorServlet.kt:125)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    at kotlinx.coroutines.DispatchedKt.resumeCancellable(Dispatched.kt:410)
    at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)
    at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:109)
    at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:160)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:52)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at io.ktor.server.servlet.KtorServlet.blockingService(KtorServlet.kt:96)
    at io.ktor.server.servlet.KtorServlet.service(KtorServlet.kt:57)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:848)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1772)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1759)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at com.google.apphosting.runtime.jetty9.ParseBlobUploadHandler.handle(ParseBlobUploadHandler.java:119)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1182)
    at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doHandle(AppEngineWebAppContext.java:183)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
    at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:296)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
    at org.eclipse.jetty.server.Server.handle(Server.java:539)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333)
    at com.google.apphosting.runtime.jetty9.RpcConnection.handle(RpcConnection.java:202)
    at com.google.apphosting.runtime.jetty9.RpcConnector.serviceRequest(RpcConnector.java:81)
    at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:123)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:695)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:658)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:628)
    at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run(JavaRuntime.java:820)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:269)
    at java.lang.Thread.run(Thread.java:748)
我测试过:

  • 启用计费
  • 从头开始创建新项目
  • 改用com.google.firebase:firebase管理包(版本6.7.0)(结果相同)
  • 改为使用数据存储(这似乎很好,但从Firestore切换需要我移动整个项目并重写大量代码)

我在App Engine Flex环境中运行时遇到了类似的问题,最终发现Flex提供的默认实例大小(0.6 GB)太小,无法支持Firestore API。因此,在Flex中,我需要调整我的app.yaml文件,以包含一个“参考资料”部分,如下所示:

resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
有关App Engine灵活部署中资源设置的参考:

对于appenginestandard,我希望您可能需要通过调整App-Engine.xml文件中的“instance class”来执行类似的操作。“F1”是App Engine标准中的默认实例类,Java 8运行时有128 MB的限制,Java 11运行时有256 MB的限制。因此,您可能希望尝试移动到“F2”或“F4”

有关在App Engine标准java部署中配置实例类的参考:


关于App Engine实例类的参考:

我在App Engine Flex环境中运行时遇到类似问题,最终发现Flex提供的默认实例大小(0.6 GB)太小,无法支持Firestore API。因此,在Flex中,我需要调整我的app.yaml文件,以包含一个“参考资料”部分,如下所示:

resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
有关App Engine灵活部署中资源设置的参考:

对于appenginestandard,我希望您可能需要通过调整App-Engine.xml文件中的“instance class”来执行类似的操作。“F1”是App Engine标准中的默认实例类,Java 8运行时有128 MB的限制,Java 11运行时有256 MB的限制。因此,您可能希望尝试移动到“F2”或“F4”

有关在App Engine标准java部署中配置实例类的参考:


关于应用程序引擎实例类的参考:

您可以发布application.conf文件吗?@Moinkhan,当然可以。我已经用application.conf文件的内容更新了帖子。可能是您的代码引发了异常。。。你能用试一试吗。。。并在catch子句中用空字符串进行响应。@Moinkhan,我刚刚尝试捕获测试代码的所有异常,但得到的结果与以前相同。您可以发布application.conf文件吗?@Moinkhan,当然可以。我已经用application.conf文件的内容更新了帖子。可能是您的代码引发了异常。。。你能用试一试吗。。。并在catch子句中用空字符串进行响应。@Moinkhan,我刚刚尝试捕获测试代码的所有异常,但得到了与以前相同的结果。