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

HTTP response is not correct json encoded if the grpc return stream of objects. #481

Closed
lingwangsj opened this issue Nov 2, 2017 · 12 comments

Comments

@lingwangsj
Copy link

I run the examples, then:
POST http://{{host}}:{{port}}/v1/example/a_bit_of_everything/bulk with payload {"uuid": "1234"}.

after that I run
GET http://{{host}}:{{port}}/v1/example/a_bit_of_everything the http response is {"result": {"uuid":"7d96031c1eaeffa392245718677778755db9c0f267b66a75"}}, everything is great.

then I do another POST
POST http://{{host}}:{{port}}/v1/example/a_bit_of_everything/bulk with payload {"uuid": "abcd"}.

now the GET return
{"result":{"uuid":"7d96031c1eaeffa392245718677778755db9c0f267b66a75"}}{"result":{"uuid":"7e96031c1eaeffa392245718677778755db9c0f267b66a75"}}

the response body is no longer a valid JSON string.

@achew22
Copy link
Collaborator

achew22 commented Nov 2, 2017

Can you tell me if reverting b0be3cd fixes the problem?

@lingwangsj
Copy link
Author

After reverting the line in the runtime/handler.go, I got response with a new line between two results like this. It is still not a valid JSON string.
{"result":{"uuid":"0f41e1059fafe87988473bd1531f5749feff4b019fa4e248"}}
{"result":{"uuid":"0c41e1059fafe87988473bd1531f5749feff4b019fa4e248"}}

@achew22
Copy link
Collaborator

achew22 commented Nov 2, 2017

Could you describe the process you used to run the examples? Did you change any code before running make?

@lingwangsj
Copy link
Author

I ran into this issue with my own grpc server and grpc gateway server. Then I want to find out whether the issue was caused by my own code. So I checked the example and I found the stream.proto has the same API pattern as my service. So this is what I did.

I did the three go get commands mentioned in the readme

go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go

I run the example grpc server using command:
/usr/local/go/bin/go run /home/ling/Projects/go/src/github.com/grpc-ecosystem/grpc-gateway/examples/server/cmd/example-server/main.go

I run the proxy using command:

/usr/local/go/bin/go run /home/ling/Projects/go/src/github.com/grpc-ecosystem/grpc-gateway/examples/main.go

@lingwangsj
Copy link
Author

I actually run make, then restarted the grpc server and the proxy. now I got empty response. (with the runtime/handler.go changes I made before.

@achew22
Copy link
Collaborator

achew22 commented Nov 2, 2017

This is very strange. When I'm running this on my desktop I don't have this problem. Can you try running the e2e test that is in the Makefile?

@lingwangsj
Copy link
Author

Could you tell me how to run the e2e test?

@achew22
Copy link
Collaborator

achew22 commented Nov 3, 2017

You can use the .travis.yml files as a guide. Run the operations in the script and before-script section

grpc-gateway/.travis.yml

Lines 25 to 32 in b0be3cd

before_script:
- sh -c 'cd examples/browser && npm install'
script:
- make realclean && make examples SWAGGER_CODEGEN="java -jar $HOME/local/swagger-codegen-cli.jar"
- if (go version | grep -q 1.8) && [ -z "${GATEWAY_PLUGIN_FLAGS}" ]; then test -z "$(git status --porcelain)" || (git status; git diff; exit 1); fi
- env GLOG_logtostderr=1 go test -race -v github.com/grpc-ecosystem/grpc-gateway/...
- make lint
- sh -c 'cd examples/browser && node ./node_modules/gulp/bin/gulp'

@lingwangsj
Copy link
Author

I followed the steps, after resolved few dependency issues, the test run without any failure. for what is worth, I am using "go version go1.9 linux/amd64" and centOs7.

@achew22
Copy link
Collaborator

achew22 commented Nov 4, 2017

So I'm rereading this now looking for additional clues. Is the bug is state dependent and only fails on the 2nd GET request? Do requests 3-N fail in the same way?

@lingwangsj
Copy link
Author

When there is only one record, the HTTP response payload is a good json format like this:

{"result": {"uuid":"7d96031c1eaeffa392245718677778755db9c0f267b66a75"}}

the moment I added more record, and there are multiple items returns via the stream gRpc API, the HTTP response payload is invalid. does not matter the record count is 2 or 3 or more, like this:
{"result":{"uuid":"7d96031c1eaeffa392245718677778755db9c0f267b66a75"}}{"result":{"uuid":"7e96031c1eaeffa392245718677778755db9c0f267b66a75"}}

@achew22
Copy link
Collaborator

achew22 commented Dec 9, 2017

I think this should be resolved now. Can you try it out? I'm going to preemptively close it but if you continue to have problems please reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants