GRPC-Swift 空闲流导致下一个 RPC 调用由于瞬态失败而失败并出现不可用 (14)

问题描述 投票:0回答:1

在我们的 iOS 应用程序中,我们正在使用服务器端流,该流有定期的空闲期,不会发送任何数据。闲置后短时间内,如果触发另一个一元调用,则会导致 “不可用 (14):传输变为不活动”

调用之前的连接状态仍然是 ready ,但在调用时它会更改为transientFailure,并且在重新连接后立即变为 (transientFailure ->connecting ->ready)

从 ErrorDelegate 我在触发一元调用时收到此错误:

NoSuchStream(streamID: HTTP2StreamID(31), location: "<DERIVED_DATA_PATH...>/SourcePackages/checkouts/swift-nio-http2/Sources/NIOHTTP2/ConnectionStateMachine/ConnectionStreamsState.swift:298")

在我尝试执行另一个因非活动连接而失败的 RPC 之前,是否有任何可能的方法来检测流是否存在问题?我尝试过设置 keepalive 和其他一些连接设置,但到目前为止还没有成功。

我的连接设置和一些示例代码:

        let group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
        let keepalive = ClientConnectionKeepalive(
            interval: .seconds(15),
            timeout: .seconds(10),
            permitWithoutCalls: true
        )
        
        self.connection = ClientConnection
            .usingPlatformAppropriateTLS(for: group)
            .withKeepalive(keepalive)
            .withCallStartBehavior(.waitsForConnectivity)
            .withErrorDelegate(self)
            .withConnectivityStateDelegate(self)
            .connect(host: host, port: port)

直播:

        self.service = Pricing_PricingClient(channel: self.connection)
        self.grpc.tickStream = self.service.ticksStream(streamRequest,
                                                        callOptions:
                                                            CallOptions.init(
                                                                logger: logger
                                                            )
        ){ tick in
           callback(tick)
        }

流空闲一段时间后失败的一元调用示例:

        let symbolsRequest: Pricing_SymbolsRequest = .with {
            $0.serverID = Int32(serverID)
            $0.symbols = requestSymbols
        }
        
        let call = service.symbolsData(symbolsRequest)
        let status = try! call.status.recover { _ in .processingError }.wait()
        if status.code != .ok {
            print("RPC failed: \(String(describing: status))")
        }
        do {
            let response = try call.response.wait()
            callback(response)
        } catch { }

swift grpc nio
1个回答
0
投票

你用KeepAlive解决了这个问题吗?怎么办?

© www.soinside.com 2019 - 2024. All rights reserved.