Issues with bidirectional stream via CloudFlare

11 views
Skip to first unread message

Peter Olah

unread,
Jun 7, 2024, 2:28:15 PMJun 7
to grpc.io
Hey Guys,

I've been developing a proof of concept version of a file uploader service, where the (C++) client would register a given file for upload onto the (Python) service and then it uploads chunks of that file via a bidirectional stream. It uses bidi streams, because each file chunk is requested by the server side, so the details of the upload is instrumented by the service.

It works as expected in local environment, also when it's deployed and accessing it directly (via an ip address). However i'm facing issues as soon as the service gets behind CloudFlare. It becomes unstable: the uploading of chunks sporadically stops after the client wrote a chunk. Client is waiting in the "Read" call, while the service is stuck retrieving the next element of the request_iterator. Eventually grpc.RpcError gets thrown in the service, client dies with "Received RST_STREAM with error code 2".

gRPC feature is enabled on CF under the domain's Network settings. I've tested it from free and enterprise tier too.

I suspect that i'm doing something wrong here and it fails because the timing of the messages change in the different scenarios. 

The definition of the UploadChunk endpoint:
rpc UploadChunk(stream UploadChunkRequest) returns (stream UploadChunkResponse) {}

// coming from the server side to indicate what to send
message UploadChunkResponse {
    required uint64 id = 1;
    required uint64 offset = 2;
    required uint64 size = 3;
}

// coming from the client side containg the data
message UploadChunkRequest {
    required uint64 id = 1;
    required bytes data = 2;
}


In the service side i implemented the UploadChunk handler like this: https://pastebin.com/dbNqHNJs
The client looks like this: https://pastebin.com/ayDjUfzk

Every thought or help is appreciated!

Thanks,
Peter



Reply all
Reply to author
Forward
0 new messages