Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpJson ServerSideStreaming error in EchoClient #1286

Open
Tracked by #1439
lqiu96 opened this issue Mar 30, 2023 · 1 comment
Open
Tracked by #1439

HttpJson ServerSideStreaming error in EchoClient #1286

lqiu96 opened this issue Mar 30, 2023 · 1 comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@lqiu96
Copy link
Contributor

lqiu96 commented Mar 30, 2023

For Java, we have a test case that tries to mimic an exception in the middle of the stream. The full response payload should be "The rain in Spain stays mainly on the plain!" with each word as it's own response. The Cancelled exception would come after the Spain response.

  @Test
  public void testHttpJson_serverError_receiveErrorAfterLastWordInStream() {
    String content = "The rain in Spain";
    Status cancelledStatus =
        Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build();
    ServerStream<EchoResponse> responseStream =
        httpjsonClient
            .expandCallable()
            .call(ExpandRequest.newBuilder().setContent(content).setError(cancelledStatus).build());
    Iterator<EchoResponse> echoResponseIterator = responseStream.iterator();

    assertThat(echoResponseIterator.next().getContent()).isEqualTo("The");
    assertThat(echoResponseIterator.next().getContent()).isEqualTo("rain");
    assertThat(echoResponseIterator.next().getContent()).isEqualTo("in");
    assertThat(echoResponseIterator.next().getContent()).isEqualTo("Spain");
    CancelledException cancelledException =
        assertThrows(CancelledException.class, echoResponseIterator::next);
    assertThat(cancelledException.getStatusCode().getCode()).isEqualTo(StatusCode.Code.CANCELLED);
  }

Error:

...
Caused by: com.google.api.gax.httpjson.HttpJsonStatusRuntimeException: Exception in message delivery
	at com.google.api.gax.httpjson.HttpJsonClientCallImpl.deliver(HttpJsonClientCallImpl.java:316)
	... 54 more
Caused by: com.google.api.gax.httpjson.RestSerializationException: com.google.gson.stream.MalformedJsonException: Unterminated object at line 12 column 26 path $[3].severity
	at com.google.api.gax.httpjson.ProtoMessageJsonStreamIterator.next(ProtoMessageJsonStreamIterator.java:131)
	at com.google.api.gax.httpjson.HttpJsonClientCallImpl.consumeMessageFromStream(HttpJsonClientCallImpl.java:362)
	at com.google.api.gax.httpjson.HttpJsonClientCallImpl.deliver(HttpJsonClientCallImpl.java:311)
	... 54 more
Caused by: com.google.gson.stream.MalformedJsonException: Unterminated object at line 12 column 26 path $[3].severity
	at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1659)
	at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:500)
	at com.google.gson.stream.JsonReader.peek(JsonReader.java:433)
	at com.google.api.gax.httpjson.ProtoMessageJsonStreamIterator.next(ProtoMessageJsonStreamIterator.java:82)
	... 56 more

which seems to stem from the response coming back as:

[{
  "content": "The",
  "severity": "UNNECESSARY"
},{
  "content": "rain",
  "severity": "UNNECESSARY"
},{
  "content": "in",
  "severity": "UNNECESSARY"
},{
  "content": "Spain",
  "severity": "UNNECESSARY"
}{"error":{"code":499,"message":"","details":[],"Body":"","Header":null,"Errors":null}}]

The exception above seems to be complaining that there is a missing , between the payload and the error message, which I believe is caused from:
EchoService impl:

func (s *echoServerImpl) Expand(in *pb.ExpandRequest, stream pb.Echo_ExpandServer) error {

A few questions:
Would an exception that comes back in the middle of stream come back as a json response? Or would we have an expectation that the trailer message would have an exception with Status Code 499? I see from the local debugging that the status code currently comes back as a 200 (which I believe is due to https://cs.opensource.google/go/go/+/refs/tags/go1.17.1:src/net/http/server.go;l=120-126)

What should the correct behavior be?

@lqiu96 lqiu96 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 30, 2023
@lqiu96
Copy link
Contributor Author

lqiu96 commented Mar 31, 2023

Server-side streaming test is ignored as of now: googleapis/sdk-platform-java#1588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

1 participant