我正在使用getHttpsCallable
来在Android上调用云函数,但是如果使用时间超过10秒,该函数将返回FirebaseFunctionsException: DEADLINE_EXCEEDED
错误。当我在Firebase(服务器端)上检查时,它显示功能已完成(没有任何错误)。
注意:此功能在iOS上可以正常使用,在10秒钟后在Android上无法使用
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)
在okhttp3.RealCall $ AsyncCall.execute(RealCall.java:215)
在okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641)
在java.lang.Thread.run(Thread.java:764)
引起原因:java.net.SocketTimeoutException:超时
在okhttp3.internal.http2.Http2Stream $ StreamTimeout.newTimeoutException(Http2Stream.java:656)
在okhttp3.internal.http2.Http2Stream $ StreamTimeout.exitAndThrowIfTimedOut(Http2Stream.java:664)处
W / System.err:位于okhttp3.internal.http2.Http2Stream.takeHeaders(Http2Stream.java:153)
在okhttp3.internal.http2.Http2Codec.readResponseHeaders(Http2Codec.java:131)
在okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
在okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
W / System.err:位于okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
在okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
在okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
在okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
在okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
在okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
在okhttp3.RealCall $ AsyncCall.execute(RealCall.java:200)
...另外4个
更新: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 Functions在10秒后在客户端提供超时,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56977242/