grpc / grpc-swift

The Swift language implementation of gRPC.
Apache License 2.0
2.04k stars 420 forks source link

Getting error unknown (2) when making UnaryCall call. #2057

Open araisuki opened 1 month ago

araisuki commented 1 month ago

What are you trying to achieve?

Getting error unknown (2) when making UnaryCall call.

What have you tried so far?

The request doesn't seems to be reaching our server.

glbrntt commented 1 month ago

Could you provide more information about what you're doing, how you're trying to do it and where you're seeing the error?

There isn't anything actionable we can do with the information you have provided.

araisuki commented 1 month ago

@glbrntt This how my code is

let clientConnectionHost = SukiAmbientCoreManager.shared.environment.getSocketConntectionHost()
let clientConnectionPort = 443
micChannel = ClientConnection.usingPlatformAppropriateTLS(for: group)
            .connect(host: clientConnectionHost, port: clientConnectionPort)
sdpServiceClient = Suki_Pb_Sdp_SDPServiceNIOClient.init(channel: micChannel)
        sdpServiceClient.defaultCallOptions.customMetadata.add(name: "ambient_session_id", value: recordingId)
        sdpServiceClient.defaultCallOptions.customMetadata.add(name:"sdp_suki_token",
                                                               value: TokenManager.shared.getToken() ?? "")
        micChannel.connectivity.delegate = delegate

Below how I am making an GRPC call

var request = Suki_Pb_Sdp_AuthenticationRequest()
        request.partnerID = partnerId
        request.partnerToken = partnerToken
        let task = self.sdpServiceClient.authenticate(request)
        task.response.whenComplete { result in
            switch result {
            case .success(let response):
                completionHandler(.success(response))
                break
            case .failure(let error):
                print(error)
                completionHandler(.failure(error))
                break
            }
        }

Here how authenticate UnaryRPC looks like. This is compiler generated code.

internal func authenticate(
    _ request: Suki_Pb_Sdp_AuthenticationRequest,
    callOptions: CallOptions? = nil
  ) -> UnaryCall<Suki_Pb_Sdp_AuthenticationRequest, Suki_Pb_Sdp_AuthenticationResponse> {
    return self.makeUnaryCall(
      path: Suki_Pb_Sdp_SDPServiceClientMetadata.Methods.authenticate.path,
      request: request,
      callOptions: callOptions ?? self.defaultCallOptions,
      interceptors: self.interceptors?.makeAuthenticateInterceptors() ?? []
    )
  }
araisuki commented 1 month ago

And also it happens only for my client using the app, If I use app with the same account it works fine. I suspect is it something to do with the network? But instead of unknown(2) error some valid error might be useful to understand

glbrntt commented 1 month ago

unknown is a valid gRPC status code. It's possible the server returned an error with this status to the client.

Is there a message with the error?