android - Firebase 函数在 10 秒后在客户端超时

标签 android firebase google-cloud-functions

我使用 getHttpsCallable 在 Android 上调用云函数,但如果花费时间超过 10 秒,该函数会返回 FirebaseFunctionsException: DEADLINE_EXCEEDED 错误。当我检查 firebase(服务器端)时,它显示功能已完成(没有任何错误)。

注意:此功能在 iOS 上完美运行,在 Android 上 10 秒后失败

I tried this solution here as issue appears similar to this one但如果超过 10 秒,函数仍然会失败。

我在 gradle 中使用最新的依赖项,

dependencies {
    // 
    implementation 'com.google.firebase:firebase-functions:18.0.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-auth:18.0.0'
    implementation 'com.google.firebase:firebase-storage:18.0.0'
}

她的职责是我的,

HttpsCallableReference ref = mFunctions.getHttpsCallable("myFirebaseFunction");
ref.setTimeout(600, TimeUnit.SECONDS);
ref.call(Data)
    .addOnSuccessListener(new OnSuccessListener<HttpsCallableResult>() {
                @Override
                public void onSuccess(HttpsCallableResult httpsCallableResult) {
                    Gson jsonData = new Gson();
                    String json = jsonData.toJson(httpsCallableResult.getData());
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    e.printStackTrace();
                }
            });

这是堆栈跟踪日志,

W/System.err: com.google.firebase.functions.FirebaseFunctionsException: DEADLINE_EXCEEDED W/System.err: at com.google.firebase.functions.FirebaseFunctions$2.onFailure(com.google.firebase:firebase-functions@@17.0.0:258) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:215) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) Caused by: java.net.SocketTimeoutException: timeout at okhttp3.internal.http2.Http2Stream$StreamTimeout.newTimeoutException(Http2Stream.java:656) at okhttp3.internal.http2.Http2Stream$StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:664) W/System.err: at okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:153) at okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:131) at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) W/System.err: at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:200) ... 4 more

更新:Firebase 控制台日志

 [
 {
   "textPayload": "Function execution took 37358 ms, finished with status code: 200",
   "insertId": "000000-a5fca827-1905-4416-b053-206981a2e5a7",
   "resource": {
     "type": "cloud_function",
     "labels": {
       "function_name": "getBookContentByIdAndDate_v2",
       "project_id": "apotex360",
       "region": "us-central1"
     }
   },
   "timestamp": "2019-07-11T14:23:51.509329740Z",
   "severity": "DEBUG",
   "labels": {
     "execution_id": "5zxmtpmy8gho"
   },
   "logName": "projects/apotex360/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
   "trace": "projects/apotex360/traces/98f9c62f094ff33f4e0524c9231fe126",
   "receiveTimestamp": "2019-07-11T14:23:57.750633081Z"
 },
 {
   "textPayload": "stream finished",
   "insertId": "000000-914deed7-d813-4f86-93d8-7f72d3377e1c",
   "resource": {
     "type": "cloud_function",
     "labels": {
       "project_id": "apotex360",
       "region": "us-central1",
       "function_name": "getBookContentByIdAndDate_v2"
     }
   },
   "timestamp": "2019-07-11T14:23:51.506Z",
   "severity": "INFO",
   "labels": {
     "execution_id": "5zxmtpmy8gho"
   },
   "logName": "projects/apotex360/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
   "trace": "projects/apotex360/traces/98f9c62f094ff33f4e0524c9231fe126",
   "receiveTimestamp": "2019-07-11T14:23:57.750633081Z"
 },
 {
   "textPayload": "Function execution started",
   "insertId": "000000-409caeb7-96cd-4d27-b2b7-ed0546f919be",
   "resource": {
     "type": "cloud_function",
     "labels": {
       "project_id": "apotex360",
       "region": "us-central1",
       "function_name": "getBookContentByIdAndDate_v2"
     }
   },
   "timestamp": "2019-07-11T14:23:14.151990344Z",
   "severity": "DEBUG",
   "labels": {
     "execution_id": "5zxmtpmy8gho"
   },
   "logName": "projects/apotex360/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
   "trace": "projects/apotex360/traces/98f9c62f094ff33f4e0524c9231fe126",
   "receiveTimestamp": "2019-07-11T14:23:20.439670300Z"
 }
]

我在这里缺少什么吗?我真的很感激任何帮助。

最佳答案

这是 Android 客户端库中的一个错误,涉及 OKHTTP 可用的不同类型的超时。您可以在此处阅读有关修复的信息:

https://github.com/firebase/firebase-android-sdk/issues/604

关于android - Firebase 函数在 10 秒后在客户端超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56977242/

相关文章:

Android Studio - 首次在设备上运行应用程序时出现新遗留异常

android - Firestore 文档 get() 性能

javascript - 无法部署 Firestore Cloud Function

node.js - CloudFunctions :TypeError: storage. ref 中的 FirebaseStorage 不是函数

seo - 我如何克服使用客户端 JS 和 FireBase 呈现内容对 SEO 的影响?

firebase - 如何在 Firebase 云函数处理程序中设置主题过滤器?

java - 如何获取文件的引用

android - Android 中的自动滚动 TextView

android - 更改为异步存储后如何保存和更新应用程序

javascript - 使用 Angular 将 Firestore 数据放入数组中