googleapis / googleapis/gapic-showcase
rest streaming JSON response error
- Dominant language
- Go
- Stars
- 183
- Forks
- 55
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 8
Description
The gapic showcase tests added in [this python PR](https://github.com/googleapis/gapic-generator-python/pull/1764) uncovered an issue with the gapic showcase server. It seems that when using the StreamingSequence server in rest mode, if you request partial data before raising an error, it results in a broken JSON response
## Reproduction
```
# start a showcase server
gapic-showcase run
```
In a separate terminal:
```
# create a new sequence on the server
gapic-showcase sequence create-streaming-sequence --streaming_sequence.content "once upon a time there was a" --streaming_sequence.responses '{"status": {"code": 12, "message":"error"}, "response_index": 5}'
# create a rest attempt
curl -X POST http://localhost:7469/v1beta1/streamingSequences/0:stream -H 'x-goog-request-params: name=streamingSequences/0' -H 'Content-Type: application/json' -H 'x-goog-api-client: gl-python/3.9.2 rest/2.28.1 gax/2.11.1 gapic/0.0.0' -d '{}'
```
we get:
```
[{
"content": "once"
},{
"content": "upon"
},{
"content": "a"
},{
"content": "time{"error":{"code":501,"message":"error","details":[],"Body":"","Header":null,"Errors":null}}"
},{
"content": "there"
}]
```
we'd expect something like:
```
[{
"content": "once"
},{
"content": "upon"
},{
"content": "a"
},{
"content": "time"
},{
"content": "there"
},{
"error":{"code":501,"message":"error","details":[],"Body":"","Header":null,"Errors":null}
}]
```
## Speculation
Looking though the showcase server code, it looks like [stream.send](https://github.com/googleapis/gapic-showcase/blob/c6512469703a716c619058249f2bb55d81c5ee37/server/services/sequence_service.go#L253) and [ReportGRPCError](https://github.com/googleapis/gapic-showcase/blob/c6512469703a716c619058249f2bb55d81c5ee37/server/genrest/sequenceservice.go#L450C11-L450C26) are relevant. They seem to be using different methods to write to the same buffer. Maybe we need to change the flushing strategy?
Contributor guide
Assessment
This issue has not been assessed yet.