소스 검색

Fix handling of gRPC errors when the stream is finished

- Handle the gRPC errors if the assigned QNetworkReply is finished
  without network error and send the QGrpcStream::finish() signal
  if no gRPC error received from server.
- Cancel all gRPC streams when re-attaching the channel.

Fixes #259
Alexey Edelev 2 년 전
부모
커밋
072af6ab32
2개의 변경된 파일15개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 0
      src/grpc/qabstractgrpcclient.cpp
  2. 12 2
      src/grpc/qgrpchttp2channel.cpp

+ 3 - 0
src/grpc/qabstractgrpcclient.cpp

@@ -68,6 +68,9 @@ void QAbstractGrpcClient::attachChannel(const std::shared_ptr<QAbstractGrpcChann
     }
     dPtr->channel = channel;
     dPtr->serializer = channel->serializer();
+    for (auto stream : dPtr->activeStreams) {
+        stream->cancel();
+    }
 }
 
 QGrpcStatus QAbstractGrpcClient::call(const QString &method, const QByteArray &arg, QByteArray &ret)

+ 12 - 2
src/grpc/qgrpchttp2channel.cpp

@@ -351,9 +351,19 @@ void QGrpcHttp2Channel::stream(QGrpcStream *grpcStream, const QString &service,
             qProtoDebug() << "Remote server closed connection. Reconnect silently";
             stream(grpcStream, service, client);
             break;
-        case QNetworkReply::NoError:
-            //Reply closed without error
+        case QNetworkReply::NoError: {
+            // Reply is closed without network error, but may contain an unhandled data
+            // TODO: processReply returns the data, that might need the processing. It's should be taken into account in
+            // new HTTP/2 channel implementation.
+            QGrpcStatus::StatusCode grpcStatus;
+            QGrpcHttp2ChannelPrivate::processReply(networkReply, grpcStatus);
+            if (grpcStatus != QGrpcStatus::StatusCode::Ok) {
+                grpcStream->error(QGrpcStatus{grpcStatus, QString::fromUtf8(networkReply->rawHeader(GrpcStatusMessage))});
+            } else {
+                grpcStream->finished();
+            }
             break;
+        }
         default:
             grpcStream->error(QGrpcStatus{StatusCodeMap.at(networkError), QString("%1 call %2 stream failed: %3").arg(service).arg(grpcStream->method()).arg(errorString)});
             break;