grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.68k stars 765 forks source link

grpc-web react native android got http response at 400 or 500 level #383

Open kyktommy opened 6 years ago

kyktommy commented 6 years ago

I run grpc-web example: hello world in react native android. Then I got http response at 400 or 500 level, no problem in iOS. Envoy log response status: 503

react-native: 0.57.4 grpc-web: 1.0.2

Anyone successfully run in android?

wenbozhu commented 6 years ago

We don't have much experience on using grpc-web on RN, although we are pretty sure that google-closure is compatible with RN. The error status may be caused by the client environment?

Keep us updated, and it's good to know that iOS works fine.

kyktommy commented 6 years ago

Here is the envoy debug log in android which is not success: some headers are different from success log, is does matter?

[2018-11-20 02:16:35.530][000014][debug][http] [source/common/http/conn_manager_impl.cc:515] [C0][S14577607794600627928] request headers complete (end_stream=false):
':authority', '192.168.1.15:8080'
':path', '/helloworld.Greeter/SayHello'
':method', 'POST'
'accept', 'application/grpc-web-text'
'x-user-agent', 'grpc-web-javascript/0.1'
'x-grpc-web', '1'
'content-type', 'application/grpc-web-text; charset=utf-8'
'content-length', '16'
'connection', 'Keep-Alive'
'accept-encoding', 'gzip'
'user-agent', 'okhttp/3.11.0'

[2018-11-20 02:16:35.530][000014][debug][router] [source/common/router/router.cc:262] [C0][S14577607794600627928] cluster 'greeter_service' match for URL '/helloworld.Greeter/SayHello'
[2018-11-20 02:16:35.530][000014][debug][router] [source/common/router/router.cc:318] [C0][S14577607794600627928] router decoding headers:
':authority', '192.168.1.15:8080'
':path', '/helloworld.Greeter/SayHello'
':method', 'POST'
':scheme', 'http'
'accept', 'application/grpc-web-text'
'x-user-agent', 'grpc-web-javascript/0.1'
'x-grpc-web', '1'
'content-type', 'application/grpc-web-text; charset=utf-8'
'content-length', '16'
'accept-encoding', 'gzip'
'user-agent', 'okhttp/3.11.0'
'x-forwarded-proto', 'http'
'x-request-id', '88013576-8ad1-4e62-a7c6-ca749d7475a4'
'x-envoy-expected-rq-timeout-ms', '15000'

[2018-11-20 02:16:35.530][000014][debug][client] [source/common/http/codec_client.cc:26] [C2] connecting
[2018-11-20 02:16:35.530][000014][debug][connection] [source/common/network/connection_impl.cc:634] [C2] connecting to 192.168.1.15:9090
[2018-11-20 02:16:35.531][000014][debug][connection] [source/common/network/connection_impl.cc:643] [C2] connection in progress
[2018-11-20 02:16:35.531][000014][debug][http2] [source/common/http/http2/codec_impl.cc:639] [C2] setting stream-level initial window size to 268435456
[2018-11-20 02:16:35.531][000014][debug][http2] [source/common/http/http2/codec_impl.cc:661] [C2] updating connection-level initial window size to 268435456
[2018-11-20 02:16:35.531][000014][debug][pool] [source/common/http/http2/conn_pool.cc:98] [C2] creating stream
[2018-11-20 02:16:35.531][000014][debug][router] [source/common/router/router.cc:1000] [C0][S14577607794600627928] pool ready
[2018-11-20 02:16:35.531][000014][debug][http] [source/common/http/conn_manager_impl.cc:888] [C0][S14577607794600627928] request end stream
[2018-11-20 02:16:35.533][000014][debug][connection] [source/common/network/connection_impl.cc:516] [C2] connected
[2018-11-20 02:16:35.533][000014][debug][client] [source/common/http/codec_client.cc:64] [C2] connected
[2018-11-20 02:16:35.541][000014][debug][http2] [source/common/http/http2/codec_impl.cc:515] [C2] stream closed: 2
[2018-11-20 02:16:35.541][000014][debug][client] [source/common/http/codec_client.cc:105] [C2] request reset
[2018-11-20 02:16:35.541][000014][debug][pool] [source/common/http/http2/conn_pool.cc:190] [C2] destroying stream: 0 remaining
[2018-11-20 02:16:35.541][000014][debug][router] [source/common/router/router.cc:471] [C0][S14577607794600627928] upstream reset
[2018-11-20 02:16:35.541][000014][debug][http] [source/common/http/conn_manager_impl.cc:1096] [C0][S14577607794600627928] encoding headers via codec (end_stream=false):
':status', '503'
'content-length', '57'
'content-type', 'text/plain'
'date', 'Tue, 20 Nov 2018 02:16:35 GMT'
'server', 'envoy'

And here is iOS success debug log:

[2018-11-20 02:17:57.831][000013][debug][http] [source/common/http/conn_manager_impl.cc:515] [C3][S12275470240448904873] request headers complete (end_stream=false):
':authority', '192.168.1.15:8080'
':path', '/helloworld.Greeter/SayHello'
':method', 'POST'
'content-type', 'application/grpc-web-text'
'user-agent', 'pokapp/1 CFNetwork/901.1 Darwin/18.0.0'
'connection', 'keep-alive'
'x-grpc-web', '1'
'accept', 'application/grpc-web-text'
'accept-language', 'en-us'
'content-length', '16'
'accept-encoding', 'gzip, deflate'
'x-user-agent', 'grpc-web-javascript/0.1'

[2018-11-20 02:17:57.831][000013][debug][router] [source/common/router/router.cc:262] [C3][S12275470240448904873] cluster 'greeter_service' match for URL '/helloworld.Greeter/SayHello'
[2018-11-20 02:17:57.831][000013][debug][router] [source/common/router/router.cc:318] [C3][S12275470240448904873] router decoding headers:
':authority', '192.168.1.15:8080'
':path', '/helloworld.Greeter/SayHello'
':method', 'POST'
':scheme', 'http'
'content-type', 'application/grpc'
'user-agent', 'pokapp/1 CFNetwork/901.1 Darwin/18.0.0'
'x-grpc-web', '1'
'accept', 'application/grpc-web-text'
'accept-language', 'en-us'
'accept-encoding', 'gzip, deflate'
'x-user-agent', 'grpc-web-javascript/0.1'
'x-forwarded-proto', 'http'
'x-request-id', '44564fcf-4876-47f2-9ec3-04ae4243667e'
'te', 'trailers'
'grpc-accept-encoding', 'identity,deflate,gzip'

[2018-11-20 02:17:57.831][000013][debug][client] [source/common/http/codec_client.cc:26] [C4] connecting
[2018-11-20 02:17:57.831][000013][debug][connection] [source/common/network/connection_impl.cc:634] [C4] connecting to 192.168.1.15:9090
[2018-11-20 02:17:57.831][000013][debug][connection] [source/common/network/connection_impl.cc:643] [C4] connection in progress
[2018-11-20 02:17:57.831][000013][debug][http2] [source/common/http/http2/codec_impl.cc:639] [C4] setting stream-level initial window size to 268435456
[2018-11-20 02:17:57.831][000013][debug][http2] [source/common/http/http2/codec_impl.cc:661] [C4] updating connection-level initial window size to 268435456
[2018-11-20 02:17:57.831][000013][debug][pool] [source/common/http/http2/conn_pool.cc:98] [C4] creating stream
[2018-11-20 02:17:57.831][000013][debug][router] [source/common/router/router.cc:1000] [C3][S12275470240448904873] pool ready
[2018-11-20 02:17:57.831][000013][debug][http] [source/common/http/conn_manager_impl.cc:888] [C3][S12275470240448904873] request end stream
[2018-11-20 02:17:57.834][000013][debug][connection] [source/common/network/connection_impl.cc:516] [C4] connected
[2018-11-20 02:17:57.834][000013][debug][client] [source/common/http/codec_client.cc:64] [C4] connected
[2018-11-20 02:17:57.868][000013][debug][router] [source/common/router/router.cc:602] [C3][S12275470240448904873] upstream headers complete: end_stream=false
[2018-11-20 02:17:57.868][000013][debug][http] [source/common/http/conn_manager_impl.cc:1096] [C3][S12275470240448904873] encoding headers via codec (end_stream=false):
':status', '200'
'content-type', 'application/grpc-web-text+proto'
'grpc-accept-encoding', 'identity,deflate,gzip'
'accept-encoding', 'identity,gzip'
'x-envoy-upstream-service-time', '36'
'date', 'Tue, 20 Nov 2018 02:17:57 GMT'
'server', 'envoy'

[2018-11-20 02:17:57.868][000013][debug][client] [source/common/http/codec_client.cc:95] [C4] response complete
[2018-11-20 02:17:57.868][000013][debug][pool] [source/common/http/http2/conn_pool.cc:190] [C4] destroying stream: 0 remaining
[2018-11-20 02:17:57.868][000013][debug][http] [source/common/http/conn_manager_impl.cc:1214] [C3][S12275470240448904873] encoding trailers via codec:
'grpc-status', '0'
'grpc-message', 'OK'

[2018-11-20 02:17:57.868][000013][debug][http2] [source/common/http/http2/codec_impl.cc:515] [C4] stream closed: 0
syklevin commented 6 years ago

I think the key problem is about content-type value In android, it would append extra charset, refer to this issue

kyktommy commented 6 years ago

I think the key problem is about content-type value In android, it would append extra charset, refer to this issue

yes, grpc server log display:

I 2018-11-22T07:07:21.547Z http_server_filter.cc:197] Unexpected content-type 'application/grpc-web-text; charset=utf-8'

so I need to set mode= grpcweb in protoc, then content-type become 'application/grpc-web+proto' without charset

but mode=grpcweb can't use stream, where only receive entire streaming messages in call end.

wenbozhu commented 6 years ago

This is good to know.

We will see if we could fix the proxy to allow the appended charset string.

From what's reported on the RN issue, it seems that RN will append charset to any C-T. I wonder if +proto will prevent this behavior.

c100k commented 4 years ago

Hello guys. This issue is still hapenning on the last version of React Native (v0.63.x). Do you think we can fix the go proxy to handle this ?

I can help making a PR, I just need to know where to start from.

khanhtd02 commented 3 years ago

Any update on this issue. I am still facing with this problem on react native android?

KedwithGod commented 7 months ago

i saw similar error, instead of localhost, android uses 10.0.2.2 check https://github.com/grpc/grpc-web/issues/90#issuecomment-715573413

SerineBagdasaryan commented 1 month ago

I run grpc-web Angular17 ERROR E {message: 'Http response at 400 or 500 level, http status code: 0', stack: 'Error: Http response at 400 or 500 level, http sta…rapFn (http://localhost:4200/polyfills.js:626:35)', code: 2, metadata: {…}}