grpc-swift: Send multiple grpc requests at the same time, when one of them fails, then other requests all call back "Transport became inactive".

        let (host, port) = address.convertAddress()
        let useTLS = (port == 443)
        let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
        let builder = useTLS ? ClientConnection.usingTLSBackedByNIOSSL(on: group) : ClientConnection.insecure(group: group)
        let channel = builder.connect(host: host, port: port)
        channel.connectivity.delegate = self

We upgraded from grpc0.x to grpc1.7. When the v0.x sends multiple requests at the same time, it will not affect each other when an error occurs, and the v1.7 will call back all ‘Transport became inactive’ after the error occurs.

Is this normal? I expect multiple requests to not affect each other.

About this issue

Most upvoted comments

There is no connection delegate for the pool.

That doesn’t seem right: a 502 will be mapped to a status unavailable message and should only fail the RPC that receives the 502.

Are you sure that the 502 is the cause of the connection being closed? Do you have some logs we could look at?

When I receive the first response with a status code of 502, the ClientChannel will close the connection in the function: handleError(), and subsequent requests will fail(return with ‘Transport became inactive’) until the reconnection succeeds.

See the file: ClientTransport.swift(line:399).

 /// On-loop implementation of `handleError(_:)`.
  private func _handleError(_ error: Error) {
    self.callEventLoop.assertInEventLoop()

    switch self.state.handleError() {
    case .doNothing:
      ()

    case .propagateError:
      self.forwardErrorToInterceptors(error)
      self.failBufferedWrites(with: error)

    case .propagateErrorAndClose:
      self.forwardErrorToInterceptors(error)
      self.failBufferedWrites(with: error)
      **self.channel?.close(mode: .all, promise: nil)**
    }
  }

Do you have trace logs? (You can set logger.logLevel = .trace)