Search code examples
iosfirebasetimeoutgoogle-cloud-functionsswift4.2

Firebase cloud function responding Code=-1001 "The request timed out." all the time


I'm working on an application both in android and ios with the versions of firebase cloud function 6.5.0 in web and 2.5.1 in ios, The android side is working well but in swift i received Code=-1001 "The request timed out." every time i called my functions.

I've tried every approach of calling my functions such as calling with "functions.httpsCallable" , "alamofire" or "URLRequest" but every time i got Code=-1001 "The request timed out." error and nothing is printed in function's log. I have try with postman and it was working. I think i have problem in my code, config or the versions of my sdks.

Please help me to solve this issue.

This is my simple test api function:

exports.testApi = functions.region('europe-west1').https.onCall((data, context) => {
    const message = data.message;

    return {
        message : message
    }
});

And these are my swift codes:

let data = ["message": "test"]

G.functions.httpsCallable("testApi").call(data) { (result, error) in
    if let error = error as NSError? {
         if error.domain == FunctionsErrorDomain {
              let code = FunctionsErrorCode(rawValue: error.code)
              let message = error.localizedDescription
              let details = error.userInfo[FunctionsErrorDetailsKey]

              print("\(code!) \(message) \(String(describing: details))")
         }
    }

    if result?.data != nil {
        print("result \(result!.data)")
    }
}        

This is my G class:

class G{

static var functions = Functions.functions(region: "europe-west1")

.
.
.

this is my log

2019-07-24 23:42:07.781273+0430 AppName[3188:858764] Task <234AF689-0252-4BEC-87E1-CF376AD50E17>.<1> finished with error - code: -1001
2019-07-24 23:42:07.785188+0430 AppName[3188:858780] Task <234AF689-0252-4BEC-87E1-CF376AD50E17>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x283d489f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <234AF689-0252-4BEC-87E1-CF376AD50E17>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <234AF689-0252-4BEC-87E1-CF376AD50E17>.<1>"
), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=https://europe-west1-AppName.cloudfunctions.net/testApi, NSErrorFailingURLKey=https://europe-west1-AppName.cloudfunctions.net/testApi, _kCFStreamErrorDomainKey=4} [-1001]
2019-07-24 23:42:07.794172+0430 AppName[3188:858764] Task <234AF689-0252-4BEC-87E1-CF376AD50E17>.<1> HTTP load failed (error code: -999 [1:89])
FIRFunctionsErrorCode DEADLINE EXCEEDED nil


Solution

  • After a long time of trying everything i found out the issue. I use VPN to connect to firebase and somehow L2TP VPN's can not connect to firebase even in web console so i changed my VPN to IKEv2 and the issue was solved.