Go RPC streaming send not working properly when optional values not provided

2 weeks ago 15
ARTICLE AD BOX

I am developing an RPC streaming endpoint in Go with RPC code generated through thrift. I am having an issue where clients aren't receiving my send calls when optional values aren't provided in my response.

I've defined my Thrift IDL components like this:

struct StreamDataOverRPCRequest { 1: required string req_param 255: required base.Base Base } struct StreamDataOverRPCResponse { 1: required string resp_required_param 2: optional StaticDataStruct resp_optional_param 255: required base.BaseResp BaseResp } service StreamingService { StreamDataOverRPCResponse StreamDataOverRPC(1: StreamDataOverRPCRequest req) throws (1: ServiceException err) (streaming.mode="server") }

Which has created this response struct in Go:

type StreamDataOverRPCResponse struct { RespRequiredParam string RespOptionalParam *string BaseResp *base.BaseResp }

The optional param resp_optional_param in the response is static data that I would prefer to only send once, in the first response before I start sending the streamed data in resp_required_param. My send code looks like this:

func SendStreamedData() { data := []string{"This ", "is ", "the ","streamed ","data."} for _, chunk := range data { resp := &StreamDataOverRPCResponse{ RespRequiredParam: chunk, RespOptionalParam: nil, } err = ClientStream.Send(ctx, resp) if err != nil { return err } }

I can see from logs that the send is happening and there is not an error, but on the client side there is no data received. There is no middleware impacting the returned data that I can see, although since I'm not explicitly including the BaseResp value it's possible there is something affecting the data.

Additionally, this same request and response struct are being used on a non-streaming version of the same endpoint and there is no issue with the providing empty values in those responses.

Is there a way to send nil values for the optional data rather than having to resend the same static data in every response? When I add values for the optional params and change nothing else it works as expected.

Read Entire Article