Closed gaynetdinov closed 6 years ago
Thanks for the detailed report but unfortunately I have no knowledge of Elixir. It would also help if you could reduce the code involved, surely taking Cowboy's chunked_hello_world and making a few tiny changes would be enough to reproduce the problem in an Erlang shell. Otherwise trying to trace the modules from Gun would also help figure things out.
It seems like this issue exists only in cowboy 1.1.2 + cowlib 1.0.2. I upgraded my test elixir project to current phoenix master, so I could use cowboy 2.2 + cowlib 2.1.0 and cannot reproduce this issue anymore.
Good to know, thanks! Guess we can close this.
Hello.
I'm trying to use
gun
in proxy service, i.e. browser sends request to proxy service, proxy service (usinggun
) sends a request to another service, which responses withchunked
transfer encoding.gun
should get chunks from that service and stream it to the browser chunk by chunk. That problem is that with such setupgun
cannot properly detect end of the response and the browser does not get full response. To better demonstrate this issue I've created two repositories: https://github.com/gaynetdinov/streaming_test and https://github.com/gaynetdinov/streaming_proxy_test. These are two phoenix apps. Proxy service is localhost:4000, it sends requests to localhost:8080 usinggun
.The proxy service looks like this
https://github.com/gaynetdinov/streaming_proxy_test/blob/master/lib/streaming_proxy_test_web/controllers/page_controller.ex#L4
So
gun
sends request to the service, which sends response the following way:https://github.com/gaynetdinov/streaming_test/blob/master/lib/streaming_test_web/controllers/page_controller.ex#L4
If you open localhost:8080 in browser, you would see proper JSON. You could refresh that page many times and always get the proper JSON.
If you open proxy service localhost:4000 you would also get a proper JSON. However, if you remove at least one
:timer.sleep(100)
from the above, the response from localhost:4000 wouldn't be full and JSON in the body would be not valid. If you remove all occurrences of:timer.sleep
and open localhost:4000 again, you would see only the beginning of the response, sometimes only headers, sometimes only 2-3 first characters of the JSON body.